I am trying to run the following R code, about the calculation of the total variation distance
library(lpSolve)
f.obj <- c(0, 1, 1, 1, 0, 1, 1, 1, 0)
f.con <- matrix (c(1, 0, 0, 1, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 0, 0, 1, 0,
0, 0, 1, 0, 0, 1, 0, 0, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1
), nrow=6, byrow=TRUE)
f.dir <- c("=", "=", "=", "=", "=", "=")
f.rhs <- c(1/2, 1/3, 1/6, 1/3, 1/6,1/2)
# Now run.
lpSoln <- lp ("min", f.obj, f.con, f.dir, f.rhs)
but I get the following error:
> lpSoln
Error: object 'lpSoln' not found
Any suggestions on how to solve this issue?
Also, I thought that that package was not installed. Then, I tried to install it with:
install.packages("lpSolve")
But I got this message from the R console...
> install.packages("lpSolve")
Installing package into ‘/usr/local/lib/R/4.1/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/lpSolve_5.6.19.tar.gz'
Content type 'application/x-gzip' length 468223 bytes (457 KB)
==================================================
downloaded 457 KB
* installing *source* package ‘lpSolve’ ...
** package ‘lpSolve’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
ERROR: compilation failed for package ‘lpSolve’
* removing ‘/usr/local/lib/R/4.1/site-library/lpSolve’
Warning in install.packages :
installation of package ‘lpSolve’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/sk/m5rzd54n6_q492pn1rn_dzbh0000gn/T/Rtmp6GpqFy/downloaded_packages’
Any suggestions on how to solve this issue?
EDITED: info added after the UseR10085's comment, thanks :-)
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin20.6.0 (64-bit)
Running under: macOS Monterey 12.6
Matrix products: default
LAPACK: /usr/local/Cellar/r/4.1.2/lib/R/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2
>