covr::package_coverage reports "No such file or directory" - r

I'm trying to see the code coverage of sumbose/iRF, so I did a git clone, started an R session inside of the directory, and
> library(covr)
> package_coverage()
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In utils::install.packages(repos = NULL, lib = tmp_lib, pkg$path, :
installation of package ‘/private/tmp/iRF’ had non-zero exit status
2: In file(con, "r") :
cannot open file '/private/var/folders/ny/f06ns0d568bgf6s559z8j_9m0000gn/T/RtmpAr8dLV/R_LIBS168866d1ef32f/iRF/R/iRF': No such file or directory
However, both R CMD INSTALL iRF and install.packages('iRF', repos = NULL) installs the package as expected.

I encountered this problem too with a under-development package that is not installed. The error message has the path like this:
... /pkgname/R/pkgname': No such file or directory
where pkgname is the package name.
I used VS Code and called covr::package_coverage(), with the package folder as the working directory. I could consistently reproduce the error, and then I noticed that this error occurred if I called devtools::load_all() first.
I found that, for unknown reasons, this error disappeared if I started an R session and did not run devtools::load_all(). I did not need to (and maybe should not) load the package. covr::package_coverage() ran normally in that session without loading the package.
If I called devtools::load_all() after I called covr::package_coverage(), and then called covr::package_coverage() again, it would fail in the same session.
So I think the solution is simple, though a little bit counter intuitive:
Call covr::package_coverage() in a session that does not have the package loaded by devtools::load_all().
I could call covr::package_coverage() several times in this session without problems. Changes I made to files were reflected correctly in the output of covr::package_coverage(), without the need to loading the package.
I used covr 3.5.1, R 4.2.0 in Windows.

Related

RStudio - Not able to install packages after reinstallation of R & constant working directory issues

I recently had to have a new laptop build at work and therefore reinstalled R and R Studio through a designated 'Company Portal' that did the software installation for me (this might be the problem). When now trying to install and load packages for use, I am running in to the below error for packages (in this case for tidyverse):
Warning message: In options(stringsAsFactors = TRUE) :
'options(stringsAsFactors = TRUE)' is deprecated and will be
disabled Error in setwd("C:/R/WorkingDir") : cannot change working
directory Execution halted Warning in install.packages :
installation of package ‘tidyselect’ had non-zero exit status
I also had this error when I first loaded R up that seems to be reappearing due any attempt to install packages:
Error in setwd("C:/R/WorkingDir") :
cannot change working directory
I've never had this issue before using RStudio across numerous machines and software versions, can anyone advise what is going on? My name (and thus C:\ user file path(s)) does have an apostrophe in it, if that matters - but it has never been an issue before. Is some key installation setting now misaligned and if yes, can anyone advise how to resolve?

Install package through batch file

I am trying to share some R code with a few colleagues that are not familiar with R at all. To avoid them trying to understand R and running a script I created a batch file to just run the file without them doing anything, just double-clicking on the ".bat" file.
I've tried it and it works perfectly fine. But then I added a few lines in my Rscript to make sure the needed libraries were installed and, if not, to install them. That is when my batch file stopped working.
I've checked with another R script that just does install.packages(package_name) and the result I got is: the batch file does nothing.
So how can I run a R script that does install libraries through a batch file??
My atempt:
My extremely simple batch file:
"C:\Program Files\R\R-4.2.1\bin\R.exe" CMD BATCH "C:\Users\user\OneDrive\Documents\SomeFolder\test.R"
EXIT
And my "test.R" script:
list.of.packages <- c("lubridate","tidyverse","Z10")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
I also tried install.packages(new.packages,repos="https://cloud.r-project.org") but it doesn't work either.
Note: I know my code works because if I run it inside R it does the job.
Not sure why this doesn't work,
install.packages(new.packages,repos="https://cloud.r-project.org")
but your error message (in the comments) of
Installing package into 'C:/Users/user/AppData/Local/R/win-library/4.2' (as 'lib' is unspecified)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror Calls: install.packages -> contrib.url
Aborted execution
indicates that it isn't seeing repos. (I suspect that you had another error when you had install.packages(..., repos=) and, because you were not looking at the .Rout file you didn't see that error. But I don't know for sure.)
If the install.packages(..., repos=) isn't working, you can always set it using
options(repos = "https://cloud.r-project.org")
earlier in your batch file, and it should work.

Why do I get a "failed to lock directory" error when installing packages on my work laptop

I've recently installed R + Rstudio on my work-laptop and now I'm trying to install packages. I have full authorisation in the map that I'm downloading the packages to. However, I keep on getting the following error:
Error in install.packages : ERROR: failed to lock directory
‘\\hltfs001\Home$\jolien.jansen\Documents\R\win-library\3.6’ for
modifying. Try removing
‘\\hltfs001\Home$\jolien.jansen\Documents\R\win-library\3.6/00LOCK’
This error is accompanied by this error:
Warning in install.packages :
'lib = "\\hltfs001/Home$/jolien.jansen/Documents/R/win-library/3.6"'
is not writable
I've tried to install the packages in a different folder, which I'm also authorised to do, but that did not solve the issue.
I've googled the error and that gave me a couple of things to try.
At first I tried manually removing the LOCK folder, and restarting R. That did not help
Then I tried this code:
unlink("/hltfs001/Home$/jolien.jansen/Documents/R/win-
library/3.6/00LOCK", recursive = TRUE)
Which again removed the LOCK folder, but didn't help with the error either
Finally I tried:
install.packages("Rcpp", dependencies=TRUE, INSTALL_opts = c('--no-
lock'))
But again, that gave me the same error.
I had the same problem and I found that my problem is that my 00LOCK folder was located within an automatic-syncing Dropbox folder. So, I paused the Dropbox sync and then the problem went away after I deleted the 00LOCK folder. Apparently, the Dropbox syncing was interfering with the file locking mechanism of the installation process. So, once I finished installing the packages, I resumed my Dropbox syncing.

Error installing packages in Rstudio

I have R 3.2.2 setup installed in my system,with RStudio version 0.99.489. When I tried to install rJava package,
install.packages("rJava")
I am getting following Error:
Warning in install.packages :
downloaded length 4878 != reported length 200
Error in install.packages : subscript out of bounds
But if I run the below command before installing any package,it works fine, but I don't want to do this every time I install a package.
options(repos=structure(c(CRAN="http://cran.us.r-project.org")))
You can stick the line you want executed at every startup in your .Rprofile file which should be in your home directory. I have 3.2.3 version of R and that worked; however I do get a warning message about using a non-http version of the site.
Similarly to you, I was finding the original repository the system was using was failing to install the packages--not finding the package or downloading a file with too few bytes, perhaps because of a transient problem. You might want to consider not putting this in your .Rprofile file or commenting the line outin case this is a temporary workaround.

R CMD check warning in file.copy - missing DESCRIPTION file for unused package

I am writing a package and the R CMD check is throwing up the following errors:
* checking installed package size ... OK
Warning in file.copy(file.path(.Library, pkg, "DESCRIPTION"), pd) :
problem copying C:\R\R-31~1.2\library\lattice\DESCRIPTION to C:\Users\NEASTW~1\AppData\Local\Temp\Rtmp2pKOkh\RLIBS_2be867c654c\lattice\DESCRIPTION: No such file or directory
And
* checking loading without being on the library search path ...Warning in file.copy(file.path(.Library, pkg, "DESCRIPTION"), pd) :
problem copying C:\R\R-31~1.2\library\lattice\DESCRIPTION to C:\Users\NEASTW~1\AppData\Local\Temp\Rtmp2pKOkh\RLIBS_2be8205547c5\lattice\DESCRIPTION: No such file or directory
OK
The thing is, I am not using the lattice package anywhere within my package - to my knowledge. I have tried re-installing the lattice package to no avail. I think that the R CMD check is actually finishing ok and I don't have any WARNINGs or NOTEs, so I am not sure whether this would pass CRAN's checks?
This error came up as there was something wrong with my R installation. After re-installing it, the error was gone. Thanks goes to #hadley for helping with this issue.

Resources