Unable to access libraries in RStudio but not in R - r

I am facing a problem in RStudio when installing and using packages. I'm very very new to it so please bear with me while I describe it:
This is a new R and Rstudio installation in my PC, R version 4.1.2. For remote work due to life stuff. I usually run these same commands in my job computer with no problem (always in administrator mode).
However, when installing "readxl" to open an excel file:
> install.packages("readxl")
Installing package into ‘C:/Program Files/R/R-4.1.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/readxl_1.3.1.zip'
Content type 'application/zip' length 1717234 bytes (1.6 MB)
downloaded 1.6 MB
package ‘readxl’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘readxl’
Warning in install.packages :
problem copying C:\Program Files\R\R-4.1.2\00LOCK\readxl\libs\x64\readxl.dll to C:\Program Files\R\R-4.1.2\readxl\libs\x64\readxl.dll: Permission denied
Warning in install.packages :
restored ‘readxl’
The downloaded binary packages are in
C:\Users\Andrés RM\AppData\Local\Temp\Rtmp2RhFPr\downloaded_packages
I've read about deleting 00lockto avoid this problem but I can't find the file anywhere.
And when i check my libraries using libpath()
> .libPaths()
[1] "C:/Program Files/R/R-4.1.2" "C:/Program Files/R/R-4.1.2/library"
Then, if I want to load the library
> library(readxl)
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/my_user/Documents": The system cannot find the path specified
It returns a path that I never specified in the first place and where I don't keep any other R library.
If i try to load an excel file:
R_meristem_measures <- read_excel("C:/Users/my_user/Desktop/R meristem measures.xlsx")
Error: Evaluation error: zip file 'C:\Users\my_user\Desktop\R meristem measures.xlsx' cannot be opened.
In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/Andrés RM/Desktop/R meristem measures.xlsx": The system cannot find the path specified
After this, .libPaths()keeps returning the same results.
This happens with some other packages that I use daily (in my other computer) and the warning is the same.
However, I just tried to run this same code in native R (R x64 4.1.2) and it went perfect with no issues.
I am at a loss here. Among others I've tried sys.setenv(R_LIBS_USER)and also changing the same environment variables from the Control panel.R_LIBS="C:/R/library"also does not work.
At work I am using R 4.0 and libPaths()returns
.libPaths()
[1] "C:/Users/my_user/Documents/R/win-library/4.0" "C:/Program Files/R/R-4.0.2/library"
which is expected since my_user/etc is where i keep my packages.
Is this a problem with my computer or with something particular from RStudio? R itself works perfect but is a pain to use and I would like to use RStudio even if I can run my stuff in R console.
Thanks to everyone

Related

Error reading file while installing package devtools (R)

I've recently installed devtools looking to create my first package. At some point I tried loading the library, and got an error when 'devtools' tried to load the dependent library 'usethis'. Whenever I'd try to install it I'd get "error reading from connection". All solutions I could find online involved restarting R and my computer. Neither worked.
Finally, I manually deleted the folder, downloaded the .zip file from CRAN, and manually installed 'usethis'. I can now load 'usethis'.
I then tried loading 'devtools' but got the same error, but now for devtools.
> install.packages(pkgs = "C:/Users/.../Downloads/devtools_2.4.3.zip",repos = NULL)
Installing package into ‘C:/Users/.../OneDrive/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
package ‘devtools’ successfully unpacked and MD5 sums checked
> library(devtools)
Loading required package: usethis
Error: package or namespace load failed for ‘devtools’ in readRDS(nsInfoFilePath):
error reading from connection
In addition: Warning messages:
1: package ‘devtools’ was built under R version 4.1.3
2: package ‘usethis’ was built under R version 4.2.0
3: In readRDS(nsInfoFilePath) : error reading the file
I tried reinstalling the package, both from CRAN and manually. I restarted R and restarted my computer, all multiple times. I even reinstalled 'usethis'.
When I reinstall devtools manually the installation exists without an error. But when I actually load it, I get the error above.
My computer is a standard personal Windows PC. No fancy configurations or firewall (beyond the standard - though that shouldn't be an issue when manually installing anyway I think). I've used this same set up for months, and have installed and used dozens of packages.
Any help would be highly appreciated.

How can I install readxl package for R?

I am trying to install readxl package for R.
The following is the RStudio output:
To learn more and/or disable this warning message see the "Use secure download method for HTTP" option in Tools -> Global Options -> Packages.
> library('readxl')
Error in library("readxl") : there is no package called ‘readxl’
> install.packages("readxl")
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'
Installing package into ‘C:/Users/Lenovo/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open URL 'http://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
package ‘readxl’ is not available (for R version 3.5.0)
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/bin/windows/contrib/3.5:
cannot open URL 'http://cran.rstudio.com/bin/windows/contrib/3.5/PACKAGES'
>
The following is the R's console output:
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> install.packages("readxl")
Installing package into ‘C:/Users/Lenovo/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'); using local file 'C:/PROGRA~1/R/R-35~1.0/doc/CRAN_mirrors.csv'
Warning: unable to access index for repository https://cloud.r-project.org/src/contrib:
cannot open URL 'https://cloud.r-project.org/src/contrib/PACKAGES'
Warning: unable to access index for repository https://cloud.r-project.org/bin/windows/contrib/3.5:
cannot open URL 'https://cloud.r-project.org/bin/windows/contrib/3.5/PACKAGES'
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
InternetOpenUrl failed: ''
2: package ‘readxl’ is not available (for R version 3.5.0)
>
How can I solve this issue?
The error messages definitely seem to be telling you, that R cannot connect to download the packages. Here are some thoughts:
Does your user profile have administrative privileges? I am not a huge Windows user, but your are technically trying to add software, which sometimes requires escalated privileges. Maybe trying running R as Admin in windows, for this one issue to see if that is the problem. (Doesn't seem very likely.)
If it is a firewall issue you could try to add an exception to your firewall settings for R and/or Cran repositories.
Have your tried to account for dependent packages? install.packages("readxl", dependencies = TRUE) (This can cause its own bag of issues as well, so consider yourself forewarned.)
Can you download any other packages? As you can access the internet to make stack posts, are asking a fairly entry level question, and the URL's are valid so there may be a configuration issue with your installation of R. If all else fails, you may wish to uninstall/reinstall R on your system (and Maybe R studio while you are at it) as that may help to repair something if it is damaged. Use the file checksums, the are there for a reason.

install.packages("devtools") fails

I'm new to installing packages and R,
It looks like my devtools library is missing.
I was trying to install swirl,
I got the following message :
> install.packages("swirl")
Installing package into ‘C:/Users/cory/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (cannot open destfile 'C:\Users\cory\AppData\Local\Temp\RtmpuA5tgZ\filef6c6874433a', reason 'No such file or directory'); using local file 'C:/PROGRA~1/R/R-35~1.1/doc/CRAN_mirrors.csv'
Warning: unable to access index for repository https://cran.cnr.berkeley.edu/src/contrib:
cannot open destfile 'C:\Users\cory\AppData\Local\Temp\RtmpuA5tgZ\filef6c4b9547', reason 'No such file or directory'
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning messages:
1: package ‘swirl’ is not available (for R version 3.5.1)
2: In gzfile(file, mode) :
cannot open compressed file 'C:\Users\cory\AppData\Local\Temp\RtmpuA5tgZ/libloc_194_4cc5b48b.rds', probable reason 'No such file or directory'
I then tried the following :
> library(devtools)
Error in library(devtools) : there is no package called ‘devtools’
So I downloaded devtools in zip format and tried loading it
> getwd()
[1] "C:/Users/cory/Documents"
I downloaded the devtools zip in the same folder, and renamed it to devtoolz zip
I tried running the command again
> install.packages("devtools")
Installing package into ‘C:/Users/cory/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository http://cran.rstudio.com/src/contrib:
cannot open destfile 'C:\Users\cory\AppData\Local\Temp\RtmpuA5tgZ\filef6c77f36a9', reason 'No such file or directory'
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning messages:
1: package ‘devtools’ is not available (for R version 3.5.1)
2: In gzfile(file, mode) :
cannot open compressed file 'C:\Users\cory\AppData\Local\Temp\RtmpuA5tgZ/libloc_194_4cc5b48b.rds', probable reason 'No such file or directory'
What steps should I take to get the devtools installed?
Many thanks! :)
I found a way around this,
In case it helps someone else :
*In Rstudio, it tuns out it is possible to install a package without downloading locally and without pointing to an URL (which I also had tried). Because it is integrated with CRAN-mirrors, I was able to simply type devtools in the box and select it from the existing drop-down menu.
It proved more efficient than trying to manually import it through RGui.*
I had the same issue, I just closed my RStudio and opened it, and it worked.

Installing 'tm' package and getting a warning

I'm starting to learn R and text mining capabilities. Lately when I have been using install.packages('tm'), I get this error
Warning in install.packages :
unable to move temporary installation ‘\\HKDC01\Folder Redirection\myname\Documents\R\R-3.2.3\library\file1c1427307792\tm’ to ‘\\HKDC01\Folder Redirection\myname\Documents\R\R-3.2.3\library\tm’
The downloaded binary packages are in
C:\Users\myname\AppData\Local\Temp\RtmpsRcIY8\downloaded_packages
And when I call library(tm), I get an error as it hasn't been installed properly.

install xlsx and xlsxjars in R 3.2.0

Since today I am using the R Version 3.2.0 for statistical analysis. Today I try to install the packages "xlsx" and "xlsxjars" for my new installation but it didn't work. Every time I try to install the packages (install.packages("xlsx")) I get the following error message:
Warning in install.packages :
downloaded length 9351168 != reported length 9485172
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/xlsx_0.5.7.zip'
Content type 'application/zip' length 400857 bytes (391 KB)
downloaded 391 KB
Warning in install.packages :
error 1 in extracting from zip file
Warning in install.packages :
cannot open compressed file 'xlsxjars/DESCRIPTION', probable reason 'No such file or directory'
Error in install.packages : cannot open the Connection`
The problem only take place when I try to install the xls-packages. Other packages can be installed smoothly without any problems.
I hope there is anyone out there who had already installed the aforesaid packages in R Version 3.2.0 and can give me a short advice how to install the packages in the new R Version?
First,
setInternet2(use=TRUE)
Then install necessary packages individually:
install.packages('rJava')
install.packages('xlsxjars')
install.packages('xlsx')

Resources