2

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

Andrés R
  • 21
  • 1
  • Does this related question help? https://stackoverflow.com/a/26573219/6851825 – Jon Spring Jan 18 '22 at 18:48
  • 1
    Hi, thanks. I followed these steps and, while I was able to reinstall "readxl" package via vanilla R, rstudio prompts the same error. i loaded the library (no error message) and tried to load a file, prompting the error. it keeps looking for a path that is not where libs are at. Also I would note that this path involves an "é" which may be a character it does not recognize. however, libraries are not there anyway and libpaths() in rstudio returns the two correct ones and the error message – Andrés R Jan 18 '22 at 20:06
  • Have you tried to read your excel file by setting your working directory to where the file is? – Fla28 Jan 18 '22 at 23:09
  • 1
    Hi, thanks. Yes. I usually keep my wd separated because I want the graphs I generate stored in another folder, but I did try. Same error message and same output @Fla28 – Andrés R Jan 19 '22 at 08:45

0 Answers0