R CMD REMOVE has no effect - r

$ /usr/bin/R --vanilla CMD REMOVE xgboost
Removing from library ‘/home/arferk01/R/x86_64-pc-linux-gnu-library/3.5’
But the directory's still there:
$ ls /home/arferk01/R/x86_64-pc-linux-gnu-library/3.5/xgboost
data DESCRIPTION html libs Meta R
demo help INDEX LICENSE NAMESPACE
Likewise if I say /usr/bin/R --vanilla -e 'remove.packages("xgboost")'.
What's going on?
I'm running R 3.5.0.

I just figured it out: it was a permissions issue. I'd installed a package to my user library with root ownership because I'd forgotten the -H in sudo R CMD INSTALL. What's inscrutable is that CMD REMOVE gives no error message.

Related

How to install libpng-dev on Mac

I am trying to install the reticulate package on my Mac and it depends on the png package, which in turn depends on libpng. I installed libpng with brew but the png package fails due to a missing libpng-config:
/bin/sh: libpng-config: command not found
However I have this in /opt/homebrew/bin/libpng-config:
which libpng-config
/opt/homebrew/bin/libpng-config
I found this that specifies the need for libpng-dev but I have no idea how to install that on my Mac. Any help is appreciated.
Processes not started from a shell may not inherit environment variables from that shell. Start R in Terminal to make sure that your R process inherits PATH from the Terminal shell where you have run which. Something like
$ Rscript -e "install.packages(\"png\")"
should work, though you may need to select a CRAN mirror, in which case the above will throw an error. You can do that in the install.packages call, like so:
$ Rscript -e "install.packages(\"png\", repos = \"https://cloud.r-project.org\")"
or by setting a global option, like so:
$ Rscript -e "options(repos = \"https://cloud.r-project.org\"); install.packages(\"png\")"
For details, see the R for macOS FAQ and ?options.

R: command not found

I want to install rJava but this fails with the following suggestion:
Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run "R CMD javareconf" as root.
ERROR: configuration failed for package ‘rJava’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rJava’
* restoring previous
‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rJava’
Hence, I follow this suggestion (and the one everyone else seems to suggest) and run R CMD javereconf in the terminal but now I get the message that zsh: command not found: R.
How can I get R CMD javereconf to work?
Thanks.
EDIT: While I followed the blogpost suggested by #Till, I still struggle to run R CMD javereconf (same error). In the meantime, I figured that I should mention that I'm using MacOS Big Sur with an Apple M1 Chip.
When typing R.home() RStudio returns /Library/Frameworks/R.framework/Resources/R.
There is currently a bug in CRAN's R installation package that results in it not correctly installing symbolic links to R and Rscript for commandline use. I've just verified this by inspecting the postflight script in their 4.0.5 installation package.
Basically, there's a problem wherein the uname check doesn't know about operating system releases of 20 and above.
If your uname -r release version is over 20, this would explain why the installation silently failed. My recommendation would be to manually create the symbolic links the package is supposed to create by doing something like this:
if uname -r | grep '^2' >/dev/null; then
## 15.0 and higher don't allow messing with /usr/bin
## so use /usr/local/bin instead
if [ ! -e /usr/local/bin ]; then
mkdir -p /usr/local/bin
fi
cd /usr/local/bin
# create convenience links to R and Rscript
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
fi
I'm going to file a bug with R-project shortly.
Find the location of R and Rscript on your disk by running R.home() on Rstudio's R console.
Then, follow this guide and copy the returned location from R.home() and paste on a new line on /etc/paths.
Then, restart the terminal and run R CMD javareconf

zsh: command not found: R on terminal using Big Sur Mac

I installed R from official cran website and i can run R from the Rstudio but when i try to use R from the terminal, I get the following results:
(base) ege#Eges-MBP ~ % R
zsh: command not found: R
(base) ege#Eges-MBP ~ % RScript
zsh: command not found: RScript
How can i enable the command R and run RScript from terminal on my mac?
This is possibly due to a bug with the current version of CRAN's R installation package (present as of version 4.0.5), that affects certain versions of Big Sur. I've answered this question here: R: command not found
In short, if running uname -r gives you a release number greater than 20, then you may need to manually create symbolic links that the package installer failed to.
In short:
sudo -s
mkdir -p /usr/local/bin
cd /usr/local/bin
rm -f R Rscript
ln -s /Library/Frameworks/R.framework/Resources/bin/R .
ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .
I found a way to do this.
I first found the location of R and Rscript on my disk by running R.home() on my R console.
Then, i followed this guide and copied the returned location from R.home() and pasted on a new line on /etc/paths.
Then, i restarted the terminal and i was able to use R and Rscript commands
I had a similar issue. I was able to solve it by adding the below line (path obtained by running R.home() inside R) to my .zshrc. Thanks for the guidance.
export PATH="/Library/Frameworks/R.framework/Resources:${PATH}"
You need to add the directory where the R binaries are installed to the PATH environment variable.
You can add this in the current session as follows:
PATH=/usr/local/bin/:$PATH
To have this done automatically in every new session ensure that this line is added to your ~/.zshrc file:
export PATH="/usr/local/bin/:${PATH}"

Rstudio does not start "Unable to determine real path of R script" due to previous error during compilation of R

I am using Fedora 32, I have R (3.5.1 ) within conda. I also compiled R 4.0.0 from source but since I was having another problem with Rstudio I removed this version trying to solve these issues. (With 4.0.0 I couldn't install packages because I got an 'C++11 standard requested but CXX11 is not defined' error, I made the mistake of using --with-x=no during that compiling)
Now I tried to either compile a new version (4.0.1) or get R through yum, but every time I try to reinstall Rstudio I get this error:
Unable to determine real path of R script /home/andrespara/R-4.0.0/bin/R (system error 2 (Folder doesn'exist*))
I removed ~/.config/rstudio ~/.local/share/rstudio ~/.rstudio/ every time I removed/reinstalled Rstudio. I also searched for help in the rstudio community forums. I also
I compiled 4.0.1 with this line (deactivating conda before this avoided the X11 error that I had before)
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
I added symbolic links following these instructions https://docs.rstudio.com/resources/install-r-source/
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
R 4.0.1 is now correctly installed, I even used it today and installed some package the only missing link is with Rstudio and its installation that doesn't recognize it.
My question is how to either jump to another version of R working with Rstudio and get rid of that message when Rstudio starts.
I should add can't even start Rstudio because it still asks for the 'broken version' even when I tried to reinstall it several times.
I managed to solve this thanks to a colleague who found a workaround.
First running RSTUDIO_WHICH_R=$(which R) and then rstudio in the console bypassed the first error.
conda deactivate
RSTUDIO_WHICH_R=$(which R)
rstudio
Then knowing the launcher was the error and thanks to this answer https://askubuntu.com/a/112259/265501 I went to /usr/share/applications
and edited the line pointing to the useless binary with the correct one in the rstudio.desktop file found there.
Edit the file ~/.profile
export RSTUDIO_WHICH_R=$(which R)
The problem is that you've created a symlink from the wrong location. Rstudio launcher is looking for R in /home/andrespara/R-4.0.0/bin/R but it can't find it there. Your symlinks should be redirecting from that location to where you installed R like this:
sudo ln -s /opt/R/${R_VERSION}/bin/R home/andrespara/R-4.0.0/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript home/andrespara/R-4.0.0/bin/Rscript
If any of the directories in that file path don't exist, you'll have to create them as well.

Roxygen, package building, and use.Rd2=TRUE

I have a simple shell script that builds my Roxygen documents, builds the package, checks, then installs the newly built package on my machine. It's quite simple:
#! /bin/sh
R CMD roxygen -d myPackage
R CMD build myPackage/
R CMD check myPackage_0.01.tar.gz
R CMD INSTALL myPackage myPackage_0.01.tar.gz
But I'm having issues with Roxygen picking up my .onLoad() function as described previously on StackOverflow. The solution is to use the use.Rd2=TRUE option with roxygenize. Well I want to build from the command prompt so I changed this line
R CMD roxygen -d myPackage
to the following line which shoves a roxygenize line to R through the stdin:
echo 'require("roxygen"); roxygenize("myPackage", roxygen.dir="myPackage",
copy.package=FALSE, use.Rd2=TRUE)' | R --no-save < /dev/stdin
This seems to work just dandy. But it feels a little convoluted. Is there an easier and/or more elegant way?
I do something similar, but I use a HERE document in the shell script to make it look cleaner.
#!/bin/sh
##
##
## Must be run from the parent of the package directory (no options
## to change target of check or tarball!?!)
PACKAGE="analyzeNMON"
VERSION=$(awk -F": +" '/^Version/ { print $2 }' ${PACKAGE}/DESCRIPTION)
R --no-restore --slave <<EOR
library(roxygen)
roxygenize(package.dir="${PACKAGE}",
roxygen.dir="${PACKAGE}",
use.Rd2=TRUE,
overwrite=TRUE,
copy.package=FALSE,
unlink.target=FALSE)
EOR
R CMD build ${PACKAGE}
R CMD check ${PACKAGE}_${VERSION}.tar.gz
R CMD INSTALL ${PACKAGE}_${VERSION}.tar.gz
The R code is very similar to that in the script run during R CMD roxygen.
The roxygen that is installed on my system (version 0.1; installed from CRAN this week) doesn't seem to support the -s option mentioned above...
May be the R CMD roxygen -s option will help here. I believe it is effectively the same as setting use.Rd2=TRUE in the roxygenize function.

Resources