3

I am new to R. Can anyone tell me how can I add the lpSolve package to R on a mac for example which folder to add it to, etc?

I couldn't find anything in the documentation.

Roland
  • 127,288
  • 10
  • 191
  • 288
kartik
  • 83
  • 1
  • 3
  • 12

2 Answers2

6

You install R packages using install.packages; so try install.packages('lpSolve', repos='http://cran.rstudio.com') and let me know if you have further questions.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • ok, I did that. It says "The downloaded binary packages are in /var/folders/48/jxrps3zj12x8bn8rlpcv2dk80000gn/T//RtmpEfV38g/downloaded_packages" Now, when I try to run this: > f.obj <- c(1,9,3) > f.con <- matrix (c(1,2,3,3,2,2),nrow = 2,byrow=TRUE) > f.dir <- c("<=","<=") > f.rhs <- c(9,15) > lp("max",f.obj,f.con,f.dir,f.rhs) Error: could not find function "lp"\ – kartik Mar 10 '14 at 05:24
  • That means you've not `require(lpSolve)`... try that? – hd1 Mar 10 '14 at 05:27
  • Thanks, it worked. Just one last question, shouldn't it be lpSolve instead of ipSolve? – kartik Mar 10 '14 at 05:30
  • Hi, can you please tell me how can I do this in R. Say I have to minimize a + b and the constraints are a >= 0, b >= 0, a + b + s1 = 5. I am not looking for the value of the objective function, I am just looking the for the syntax in R. – kartik Mar 10 '14 at 07:01
  • Post a separate question. – hd1 Mar 10 '14 at 07:16
3

If your new to R I'd suggest RStudio, a visual IDE for R. We use it for teaching students basic statistics and programming in R,

RStudio Download

Inside Rstudio

Menu Tools -> Install Packages

  • Type Package Name
  • Click Install

Now, after it installs, goto the Package Tab in the slower right pane.

Check the box next to the package and it will be loaded.

I'd suggest using the "lpSolveAPI" interface to lpSolve.

Tom_N_PDX
  • 56
  • 4