Install R package to a specific directory - r

I tried this code to install R package to a directory where I stored my R packages.
install.packages("zoo", lib="/data/Rpackages/")
I got this warning message:
Warning in install.packages("zoo", lib = "/data/Rpackages/") : 'lib
= "/data/Rpackages/"' is not writable
Secondly how do I create a file .Renviron in our home area and add the line R_LIBS=/data/Rpackages/ to it?

How do you actually get out of the warning situation? Is there a better way other than (in R Studio menus) Session->Interrupt R and terminating the R session? I tried CTRL-C.
> install.packages("car", lib="/my R packages/")
Warning in install.packages :
'lib = "/my R packages/"' is not writable
My solution to the problem was to load the package within R Studio using the 'Packages' window which then does the following:
> install.packages("car")
Installing package into ‘C:/Users/33386/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.1/car_2.0-21.zip'
Content type 'application/zip' length 1332800 bytes (1.3 Mb)
opened URL
downloaded 1.3 Mb
package ‘car’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\33386\AppData\Local\Temp\RtmpKWnZD4\downloaded_packages
>

Briefly:
Use chmod to change the directory mode: chmod u+w /data/R/packages. You may need sudo (or your admin) to do that.
Use an editor and create and save a file: editor ~/.Renviron. You could also copy Renviron.site from R's etc/ directory and start from that.

Try running R studio as administrator. If you are using ubuntu start R using
sudo R

Related

installation of package ‘rmarkdown’ had non-zero exit status - How to solve that?

I am trying to install ‘rmarkdown’ in my RStudio Version 1.4.904 and R version 4.0.3 but getting the following error. I cannot open a new rmarkdown and knit a rmarkdown file. Every time I try, this message pops up,
R Markdown documents requires an updated version of the rmarkdown package. Do you want to install this package now?
Can anyone help me with that?
install.packages(ç, dependencies=TRUE)
Installing package into ‘/Users/Library/R/4.0/library’
(as ‘lib’ is unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
rmarkdown 2.3 2.4 FALSE
installing the source package ‘rmarkdown’
trying URL 'http://cran.utstat.utoronto.ca/src/contrib/rmarkdown_2.4.tar.gz'
Content type 'application/x-gzip' length 3202546 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
Warning in file(con, "r") :
cannot open file '/var/db/timezone/zoneinfo/+VERSION': No such file or directory
dyld: lazy symbol binding failed: Symbol not found: _utimensat
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib (which was built for Mac OS X 10.13)
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _utimensat
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib (which was built for Mac OS X 10.13)
Expected in: /usr/lib/libSystem.B.dylib
/Library/Frameworks/R.framework/Resources/bin/INSTALL: line 34: 30112 Done echo 'tools:::.install_packages()'
30113 Abort trap: 6 | R_DEFAULT_PACKAGES= LC_COLLATE=C "${R_HOME}/bin/R" $myArgs --no-echo --args ${args}
Warning in install.packages :
installation of package ‘rmarkdown’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/70/lgr12kdn6wn_k36sscnc0_dw0000gn/T/Rtmpmc0jUR/downloaded_packages’```
download the binary tgz (https://cran.r-project.org/web/packages/rmarkdown/index.html) and install directly from it.
It should work. I had pretty much the same issue and I solved it that way. Keep me posted!
F
I also faced a similar problem and I spent a half-day on getting the correct solution.
Step I followed:
Uninstalled the existing version
Installed updated version of R - R version 4.0.4 (2021-02-15).
Clicked on File->New file->R markdown. It asked to install Rmarkdown packages.
Noted the packages I need to install
Typed install.packages("rmarkdown", dependencies = TRUE) on R source(can be done on R console)
Then I tried installing Rmarkdown packages individually and it worked for me. Below are the packages I needed to install.
install.packages('knitr')
install.packages('tinytex')
install.packages('base64enc')
install.packages('digest')
install.packages('jsonlite')
install.packages('htmltools')
install.packages('rmarkdown')
A somewhat more technical workaround but it worked for me.
Go to https://cran.r-project.org/ select "Packages" from the menu on the right and navigate until you find the package you need.
Download the binary.zip file for your operating system and extract the files.
Copy the extracted folder into the installation directory for your packages. It should be shown somewhere in the error messages from where you attempted to install the package originally. Replace any existing files. Restart RStudio to recognize the updated versions.

Problem installing packages in R "unable to create temporary directory"

I am having problems installing packages in Rstudio, I tried to install "nortest" among others and it keeps saying the following error:
> install.packages("nortest")
Installing package into ‘C:/Users/meliv/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
'lib = "C:/Users/meliv/Documents/R/win-library/3.6"' is not writable
probando la URL
'https://cran.rstudio.com/bin/windows/contrib/3.6/nortest_1.0-4.zip'
Content type 'application/zip' length 39063 bytes (38 KB)
downloaded 38 KB
Warning in install.packages :
cannot create dir 'C:\Users\meliv\Documents\R\win-library\3.6\file408c43245306', reason 'No such file or directory'
Error in install.packages : unable to create temporary directory ‘C:\Users\meliv\Documents\R\win-library\3.6\file408c43245306’
I tried unchecking the folder's "read-only" feature but made no difference.
Hope someone can help me. Thanks
Ps. I have Windows 10
Instead of unchecking the folder's "read-only" feature, try checking the "write" permission to the user.
It worked for me. Hope it works for you as well.
[EDIT] Additionally, you can run R as an administrator, that also works.
Do the below:
Run getwd()
Run .libPaths()
Copy the directory where it says program files.
Run .libPaths(Paste the directory you copied with the quote marks)
Run .libPaths () with no argument.
Try installing your packages

Error when installing package ‘openNLPmodels.en’ in R / RStudio. Error: cannot open URL 'http://datacube.wu.ac.at/src/contrib/PACKAGES.rds'

When I try to install package ‘openNLPmodels.en’ in RStudio I get the following error messages:
I run the latest versions of RStudio an R. openNLP and openNLPdata are correctly installed. Can you help me to install the package? Thank you very much in advance.
install.packages("openNLPmodels.en", dependencies=TRUE, repos =
"http://datacube.wu.ac.at/", type = "source", INSTALL_opts = c('--no-lock'))
Warning in install.packages :
cannot open URL 'http://datacube.wu.ac.at/src/contrib/PACKAGES.rds': HTTP status was '404 Not Found'
trying URL 'http://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz'
Content type 'application/x-gzip' length 77794529 bytes (74.2 MB)
downloaded 74.2 MB
'\\WWG00M.ROOTDOM.NET\DFS\HOME\wt2rrib'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
ERROR: unable to create '\\Wwg00m.rootdom.net/dfs/HOME/WT2RRIB/R/Sentimental Analysis/openNLPmodels.en'
In R CMD INSTALL
Warning in install.packages :
installation of package ‘openNLPmodels.en’ had non-zero exit status
The problem is not installing openNLP. The problem is about manually installing the accompanying corpus in the language of your choice. Here are the options for the different languages in https://datacube.wu.ac.at/src/contrib/
openNLPmodels.da_1.5-2.tar.gz
openNLPmodels.de_1.5-2.tar.gz
openNLPmodels.en_1.5-1.tar.gz
openNLPmodels.es_1.5-1.tar.gz
openNLPmodels.it_1.5-1.tar.gz
openNLPmodels.nl_1.5-2.tar.gz
openNLPmodels.pt_1.5-2.tar.gz
openNLPmodels.sv_1.5-2.tar.gz
In your question, you are choosing English, so download the following onto your localhost: https://datacube.wu.ac.at/src/contrib/openNLPmodels.en_1.5-1.tar.gz
Manually install it into RStudio by selecting the tar.gz option:
Now you've got the English corpus installed for text mining with openNLP.

Changing packages directory in Rprofile

I have a project called "R installation info"
And a sub directory called "Project Packages".
I am trying to configure R in a manner that when I
Install a new package it will be installed to "Project Packages".
Also when I have an R session with that project I would like to see in RStudio in Packages folder only the packages that were installed in "Project Packages".
I created an Rprofile file in the project directory
And put the following lines in it:
.libPaths = paste0(getwd(),"/","Project Packages")
Sys.setenv(R_LIBS_USER = paste0(getwd(),"/","Project Packages"))
However when I started a new session with that project
And installed a new package like that:
> install.packages("magrittr")
Installing package into ‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/magrittr_1.5.zip'
Content type 'application/zip' length 155955 bytes (152 KB)
downloaded 152 KB
package ‘magrittr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Rafael Zanzoori\AppData\Local\Temp\RtmpOQWtgi\downloaded_packages
I see that the package was installed to a different directory from what I specified:
‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’
Instead of:
C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages
We can see from the following that the path for new packages is
> .libPaths
[1] "C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages"
> Sys.getenv("R_LIBS_USER")
[1] "C:/Users/Rafael Zanzoori/Documents/R Projects/R Installation info/Project Packages"
Also when I click on "install" button on package folder in RStudio
I see in "Install to Library" textbox :
‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’
Can you please help me understand why my Rprofile definitions for installing packages are ignored by R and how to fix it?
I tried to search for relevant posts but could not find anything that will help
Thanks
Rafael
Finally i managed to solve the problem
by renaming
‘C:/Users/Rafael Zanzoori/Documents/R/win-library/3.4’
to something else.
Since then R is using the definitions in my project's Rprofile.
I don't know what made R to override my project Rprofile since i didn't have any other Rprofile
But changing the old directory name solved the problem

Error installing RMySQL

It took a good amount of time to install RMySQL on my Linux machine but I was able to install it after changing environment variables and copy and paste lib.dll file.
However, I'm now trying to install RMySQL on my 64bit window machine, but so far there's no progress yet for two days. It broke down after "running command sh ./configure.win had status 127 error, and I cannot find what this means.
Can anyone shed some lights on this?
install.packages('RMySQL',type='source')
Installing package into ‘C:/Users/chu/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/RMySQL_0.9-3.tar.gz'
Content type 'application/x-gzip' length 165363 bytes (161 Kb)
opened URL
downloaded 161 Kb
* installing *source* package 'RMySQL' ...
** package 'RMySQL' successfully unpacked and MD5 sums checked
Warning: running command 'sh ./configure.win' had status 127
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/Users/chu/Documents/R/win-library/3.1/RMySQL'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.0/bin/x64/R" CMD INSTALL -l "C:\Users\chu\Documents\R\win-library\3.1" C:\Users\chu\AppData\Local\Temp\RtmpKA9e7I/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1
Warning in install.packages :
installation of package ‘RMySQL’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\chu\AppData\Local\Temp\RtmpKA9e7I\downloaded_packages’
for linux users..
install- libmysql first
sudo apt-get install libmysql++-dev
then try.
I was facing the same error. Given below is the link to a way around that worked for me.
http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/
In short, the location of library libmysqll.dll required for compilation, had to be changed from lib folder to bin folder of the home directory set for MySQL in environment variables.
By default, R uses the /tmp directory to install packages. On security conscious machines, the /tmp directory is often marked as “noexec” in the /etc/fstab file. This means that no file under /tmp can ever be executed. Packages that require compilation or that have self-inflating data will fail with the error mentioned.
The solution is to set the TMPDIR environment variable outside R (in your shell), which R will use as the compilation directory. How to do this depends on the shell. bash:
mkdir ~/tmp
export TMPDIR=~/tmp
Then R can compile and install the package.
I ran into the same problem while updating packages on Windows server for latest version of R. I solved it by installing from a .zip file vs .tar.gz.
I actually had to go through the process of first downloading the package, and then installing from it (not from mirror) for other reasons.
Here is what it looked like:
pk <- 'caTools'
download.packages(pk, "R-3.2-packages/" ,type = "win.binary")
install.packages(
dir("R-3.2-packages/",pattern=pk,full.names = TRUE),
repos = NULL,
type = "source")
Hope this helps.
Solution if anyone faced the same problem on windows:
Make sure your MYSQL_HOME environment variable is set correctly and libmysql.dll is copied to bin folder!!!
Run install.packages('RMySQL') then when the "Do you want to install from sources..." window pops up select No.
Then copy the downloaded binary packages location from console.
Go to Packages -> Install, paste the location into Package archive and click Install.

Resources