R libraries and paths - overview - r

I am using R Studio with R version 3.1.
I am a bit confused about how the overall file paths and conventions work.
If someone has a link to a good explanation that would be great.
I want to know if a package needs to be installed into the working directory ie do i need to set lib = "/xx/yy/zz" to the same place as the getwd() returns ?
I have supposedly succesfully installed RWeka --- package ‘RWeka’ successfully unpacked and MD5 sums checked
however when I try "library("RWeka") i get the
"Error in library("Rweka") : there is no package called ‘Rweka’ "
After I had installed the package it said
"package ‘RWeka’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
Installing package into ‘C:/Users/MY NAME/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
hence the question - are all packages downloaded to the place where R is installed and thats ok as long as all the code and files we are trying to access are in the set working director.
Many thanks
Here is the train
RWeka installed successfully
however library(RWeka) shows the following
install.packages("RWeka")
Installing package into ‘C:/Users/My Name/Documents/R/win-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.1/RWeka_0.4-23.zip'
Content type 'application/zip' length 535623 bytes (523 Kb)
opened URL
downloaded 523 Kb
package ‘RWeka’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\My Name\AppData\Local\Temp\RtmpOc8SpX\downloaded_packages
library(RWeka)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Error: package or namespace load failed for ‘RWeka’
So I guess the questions are
1. Something else to do other than installing Java from Java.com (have uninstalled and reinstalled no change)
2. I am using R 3.1.1

Please check if you are running R or R Studio on 32 or 64 bit version. Java and R must both be running the same version of architecture.

Andy / Prakash are correct - the function in R
Sys.getenv("R_ARCH") will tell you whether you are running the 32 bit or 64 bit version of R
64 bit java can be downloaded here.
https://www.java.com/en/download/faq/java_win64bit.xml#Java%20for%2064-bit

Related

"Powder" from Github not installing (RStudio)

I'm trying to run this piece of code from a Github read.me file
## Install
```{r,eval=FALSE}
#install.packages('devtools')
devtools::install_github('jeff324/powder',build_vignettes = TRUE)
```
However. I keep getting this error message back in the console:
Downloading GitHub repo jeff324/powder#HEAD
Installing 1 packages: tibble
Installing package into ‘C:/Users/tessc/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/tibble_3.0.6.zip'
Content type 'application/zip' length 836388 bytes (816 KB)
downloaded 816 KB
package ‘tibble’ successfully unpacked and MD5 sums checked
Error: Failed to install 'powder' from GitHub:
(converted from warning) cannot remove prior installation of package ‘tibble’
>
Does anyone know what might be happening?
First thing I do when I get these types of errors is to Restart R. Go to Session -> Restart R. If that doesn't work, try opening a brand new session in R Studio. I was just able to install this package. So fundamentally, it is working.

Trouble Installing rlang and TidyVerse

I am using RGui 3.5.1 and RStudio 1.2.5. I am trying to load Tidyverse and it gave some error message about "onload failed in loadNameSpace() for 'rlang' " so I think maybe I need to load rlang first, but I got the same error message.
I have been going around the circle for days now, tried everything suggested online, except to uninstall the R studio as we need to go through IT for it (R is in local software center which we are able to download ourselves so I did uninstall R and install it myself but its still not working).
Following advice found online,
I deleted rlang then checked on R:
library("rlang")
Error in library("rlang") : there is no package called ‘rlang’
Then I made sure the CRANExtra is removed
setRepositories()
Then I specified the library location to install
install.packages("rlang",lib="C:/Users/LIN0001/DataNow/Home/R/win-library/3.5")
trying URL 'https://mran.microsoft.com/snapshot/2018-08-01/bin/windows/contrib/3.5/rlang_0.2.1.zip'
Content type 'application/zip' length 821580 bytes (802 KB)
downloaded 802 KB
package ‘rlang’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\LIN0001\AppData\Local\Temp\RtmpigNMZO\downloaded_packages
---Then I try to load it from the same folder:
library("rlang",lib.loc="C:/Users/LIN0001/DataNow/Home/R/win-library/3.5")
Error: package or namespace load failed for ‘rlang’:
.onLoad failed in loadNamespace() for 'rlang', details:
call: dots_list(...)
error: object 'rlang_dots_list' not found
I also unticked the "use secure download method for http" of packages option in RStudio and when installing Tidyverse, I selected No instead of Yes on the pop up window (can't remember the exact message, something to do with security again); I have tried to load it both on R and Rstudio but got the same error messages.
Now I ran out of options to try so please help.
Many thanks in advance.

Unable to install xlsx package in Rstudio

I tried installing xlsx package in R.
install.packages("xlsx")
installing *source* package 'xlsx' ...
** package 'xlsx' successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/hi/Documents/R/win-library/3.3/xlsx'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\hi\Documents\R\win-library\3.3" C:\Users\hi\AppData\Local\Temp\RtmpSGp15V/downloaded_packages/xlsx_0.6.1.tar.gz' had status 1
Warning in install.packages :
installation of package ‘xlsx’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\hi\AppData\Local\Temp\RtmpSGp15V\downloaded_packages’
Then I ran the library function too
library(xlsx)
Error in library(xlsx) : there is no package called ‘xlsx’
To ensure that whether the package has been installed itself or not I ran
grepl("xlsx",installed.packages())
# It returns "FALSE" 649 times in a row.
I read online about how some rjava packages need to be installed as well so I tried to
install.packages('rJava')
install.packages("xlsxjars")
package ‘rJava’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\hi\AppData\Local\Temp\RtmpSGp15V\downloaded_packages
To ensure grepl("rJava",installed.packages())
Again I got "FALSE" 649 times.
I recently had a similar problem with another package and have had loads of headaches with R and Java integration. My understanding is that you have to install Java for each architecture you're using. If R is trying to install xlsx for both architectures and you've only got the 64-bit java installed, it would cause a failure like the one you got. You could try:
install.packages("xlsx", INSTALL_opts=c("--no-multiarch"))
This would keep it from trying to install the xlsx for the 32-bit architecture.
I had the same problem a few months ago. In my case, the solution was installing both versions of java (32-bit and 64-bit architecture). On windows 10 the 32-bit architecture should be installed on path ./programfiles (x86)/... and the 64-bit architecture should be installed on ./programfiles/... Both java installer can be found on the official web page.
After installing both architectures of java, it is necessary to make sure that JAVA HOME environtment is declared as empty string. Sys.getenv("JAVA HOME") = "".
This steps works for me. I hope that my solution works for you.

Unable to install sandwich package: installation of package ‘sandwich’ had non-zero exit status

I need to install the "plm" package. After installing it, the "sandwich" package was missing.
> library(plm)
Error: package or namespace load failed for ‘plm’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘sandwich
Tried to install the "sandwich" package, returned with this:
Installing package into ‘library_path’
(as ‘lib’ is unspecified)
also installing the dependency ‘zoo’
There is a binary version available but the source version is later:
binary source needs_compilation
sandwich 2.3-4 2.4-0 FALSE
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/zoo_1.8-0.zip'
Content type 'application/zip' length 901864 bytes (880 KB)
downloaded 880 KB
package ‘zoo’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\directory\downloaded_packages
installing the source package ‘sandwich’
trying URL 'https://cran.rstudio.com/src/contrib/sandwich_2.4-0.tar.gz'
Content type 'application/x-gzip' length 1280592 bytes (1.2 MB)
downloaded 1.2 MB
'\\directory\My Documents'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
* installing *source* package 'sandwich' ...
** package 'sandwich' successfully unpacked and MD5 sums checked
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
Warning in file(con, "w") :
cannot open file '\\library_path/sandwich/doc/index.html': No such file or directory
Error in file(con, "w") : cannot open the connection
ERROR: installing vignettes failed
* removing '\\library_path/sandwich'
Warning in install.packages :
running command '"C:/R-34~1.1/bin/x64/R" CMD INSTALL -l "\\library_path" C:\directory/downloaded_packages/sandwich_2.4-0.tar.gz' had status 1
Warning in install.packages :
installation of package ‘sandwich’ had non-zero exit status
The downloaded source packages are in
‘C:\directory\downloaded_packages’
Had tried:
Reinstall R and RStudio directly to C (not in C:\Program Files)
Using this command to install all the dependencies:
install.packages("sandwich", dependencies=TRUE)
Still, the "non-zero exit status" appeared. Do you have any suggestions?
I am using Windows 7 (64 bit), R 3.4.1 and RStudio 1.0.153
I think i found a temporary answer for my problem. I previously had problems related to the privilege in writing the library folder in R. Tried to work around by turning off anti-virus live update, change the security of the R folder, etc. I thought it was worked, since I did not find anymore issues on "unable to move temporary installation....". But when I restart my computer, the problem came again.
Since I am working in a university provided laptop, I need to wait until the IT grants me access as an admin. While waiting for it, I created a new library in C:/ (in my case, I named it as "R library local"). Downloaded all the package to that library
install.packages("plm", dependencies = TRUE, lib = "C:/R library local")
And load the package from the library
library("plm", lib="C:/R library local")
It works well :)
Dunno if I still need the admin access for the library in R folder or not.

Persistent problems installing the car package in R

I'm having problems installing the package car in R.
There are previous posts on the topic, including this one and this other one.
I have followed the suggestions I've come across so far without success. I am using R Version 3.2.2. and RStudio.
This is the message I get:
install.packages("car")
Installing package into ‘C:/Users/.../Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/car_2.1-3.zip'
Content type 'application/zip' length 1447213 bytes (1.4 MB)
downloaded 1.4 MB
package ‘car’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\...\AppData\Local\Temp\Rtmpc3xr5i\downloaded_packages
If I check I get,
?car
No documentation for ‘car’ in specified packages and libraries:
you could try ‘??car’
I tried installing it from R with Install packages from local zip drives, and looking for the zip in C:\Users\...\AppData\Local\Temp\Rtmpc3xr5i\downloaded_packages, but this is the result:
library(car)
Error in library.dynam(lib, package, package.lib) :
DLL ‘SparseM’ not found: maybe not installed for this architecture?
In addition: Warning message:
package ‘car’ was built under R version 3.2.5
Error: package or namespace load failed for ‘car’
I did try installing SparseM even before posting the OP without success:
> install.packages("SparseM")
Installing package into ‘C:/Users/.../Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.2/SparseM_1.7.zip'
Content type 'application/zip' length 795531 bytes (776 KB)
downloaded 776 KB
package ‘SparseM’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\...\AppData\Local\Temp\Rtmpc3xr5i\downloaded_packages
> ?SparseM
No documentation for ‘SparseM’ in specified packages and libraries:
you could try ‘??SparseM’
Follow up:
After a comment regarding R version 3.2.3 I thought it would be an easy fix to just download this version, install, and erase 3.2.2. The problem then is that RStudio did not seem to work. I un-installed and re-installed R-studio, and now I get this when opening R studio:
Without knowing what version of the car package you're using, it's hard to know exactly what the source of the problem is. It seems likely, however, that you haven't installed the proper version of the pbkrtest, on which the Rcmdr package depends.
Is there a compelling reason not to upgrade everything to their current versions, including R, all packages, and RStudio?
Best,
John

Resources