R packrat snapshot: upgrading package gives "stale" errors - r

I'm using packrat to freeze all versions of dependencies for an application. Sometimes I run into troubles with "staleness".
For instance, today I upgraded one package to a newer version. I did this by launching R in the packrat-managed project:
% R --quiet
Packrat mode on. Using library in directory:
- "~/git/myapp/app/packrat/lib"
> install.packages('MyPackage')
Installing package into ‘/Users/kwilliams/git/myapp/app/packrat/lib/x86_64-apple-darwin17.7.0/3.5.3’
(as ‘lib’ is unspecified)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3537k 100 3537k 0 0 5530k 0 --:--:-- --:--:-- --:--:-- 5527k
* installing *source* package ‘MyPackage’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (MyPackage)
The downloaded source packages are in
‘/private/var/folders/zp/hj5hqfw970z0_78mrb_802lm0001z9/T/RtmpzfYDUz/downloaded_packages’
However, when I try to generate a new snapshot file, nothing happens:
> packrat::snapshot()
Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'
(The file is no different than before - the old version of MyPackage is still listed.)
I verified that the new version was indeed installed, and try the snapshot again:
> packageVersion('MyPackage')
[1] ‘7.4’
> packrat::snapshot()
The following packages are stale:
_
MyPackage 7.4
These packages must be updated by calling packrat::restore() before
snapshotting. If you are sure you want the installed versions of these
packages to be snapshotted, call packrat::snapshot() again with
ignore.stale=TRUE.
--
Snapshot operation was cancelled, no changes were made.
Huh? Not sure why the different results between the two times.
status() does seem to know the situation correctly:
> packrat::status()
The following packages are out of sync between packrat and your current library:
packrat library
MyPackage 7.3.1-22287 7.4
Use packrat::snapshot() to set packrat to use the current library, or use
packrat::restore() to reset the library to the last snapshot.
I figure I'll force it, so I add ignore.stale=TRUE:
> packrat::snapshot(ignore.stale=TRUE)
Upgrading these packages already present in packrat:
from to
MyPackage 7.3.1-22287 7.4
Fetching sources for MyPackage (7.4) ... FAILED
Error in snapshotSources(project, activeRepos(project), allRecordsFlat) :
Errors occurred when fetching source files:
Error in getSourceForPkgRecord(pkgRecord, sourceDir, availablePkgs, repos) :
Could not find sources for MyPackage (7.4).
Bummer. Might this have something to do with the fact that this is a locally-created package, installed from a local CRAN-alike? This would be a packrat bug, because (as noted above) install.packages() can find the source package just fine.
So I think there are two potential packrat bugs here:
Inability to snapshot the newly installed package
Inability to download source for the package
FWIW, I think the first problem is identical to the situation here: https://groups.google.com/forum/#!topic/packrat-discuss/HvD45u6w4Zg, in which Kevin Ushey (author/maintainer of packrat) says "it's possible that the logic around 'stale' packages can just go away."

Here are the workarounds I'm using to get back on my way:
As mentioned above, use ignore.stale=TRUE to force the snapshot even when it thinks things are stale.
Copy the source package manually to packrat/src/MyPackage/.
Now it succeeds:
> packrat::snapshot(ignore.stale=TRUE)
Upgrading these packages already present in packrat:
from to
MyPackage 7.3.1-22287 7.4
Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'
The packrat/packrat.lock file has been updated correctly:
% git diff
diff --git a/app/packrat/packrat.lock b/app/packrat/packrat.lock
index 6c17020..f717d29 100644
--- a/app/packrat/packrat.lock
+++ b/app/packrat/packrat.lock
## -30,9 +30,9 ## Hash: 9772da3bc51603a19a2b75f008fd63e3
Package: MyPackage
Source: source
-Version: 7.3.1-22287
+Version: 7.4
SourcePath: lib/MyPackage
-Hash: 4fe20417f5711b3c7c90a4efe3bb4bc7
+Hash: 880a308537e8de571106893e839386f6
...

Related

After building a package, where is its zip file?

I have developed a very simple basic package called : mypackage in windows environment which contains one function
na2zero()
in R-Studio IDE i just did Build --> Clean and Rebuild resulted into below logs
==> Rcmd.exe INSTALL --preclean --no-multiarch --with-keep.source package
* installing to library 'C:/Users/NAME/Documents/R/R-4.0.0/library'
* installing *source* package 'mypackage' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'mypackage'
finding HTML links ... hello html
na2zero html
done
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mypackage)
i'm able to invoke the functions which resides in mypackage, but my question is, i want to see the location of the package, i believe the extension will be .zip
so in which folder the package (mypackage) exists.?
In RStudio, the "Install and Restart" menu item in the Build pane will install the package directly into R, without creating an archive file.
If you want to create an archive, there are two kinds of those. Use "Build Source Package" (in the "More..." menu) to create a .tar.gz file, which can be installed in any current version of R, and also some past and future ones, on any supported platform.
Use "Build Binary Package" to create a binary package. On Windows, that would be a .zip file. It is only good for Windows and a very small range of R versions (typically if you build in R version X.Y.Z, you'll be able to use it for different value of Z, but not different values of X or Y). You won't be able to use it on Linux or MacOS.
For a simple package, you should almost always use the "Source Package" format. Only when you have compiled code (C, C++, Fortran) is it a good idea to use the "Binary Package" format: your users may not have the compiler needed to install it themselves. But you'll need to match your users' R versions very carefully.
For both Source and Binary packages, RStudio will put the archive file in the same folder as your package source is in, e.g. if your package version 1.0.0 is in
path/to/mypackage, it will produce path/to/mypackage_1.0.0.zip.

roxygen2 not creating .Rd documentation

I am unable to generate .Rd documentation files for my package using RStudio and Roxygen2. First, let me mention that I have gone through similar problems posted here and have already done the following:
Roxygen2 blocks initiated at the beginning of file with a #'
Configured Build Tools>Checked generate documentation with Roxygen> Configure > Checked all fields under 'Use roxygen to generate' and 'Automatically roxygenize when running'
Made sure there were no .Rd files in the 'man' folder
And even after that, when I perform a 'Build and Reload' on RStudio I get the following output (please note the line that reads: No man pages found in package MYPACKAGE:
=
=> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
>
Updating MYPACKAGE documentation
Loading MYPACKAGE
Documentation completed
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source MYPACKAGE
installing to library C:/Users/user/Documents/R/win-library/3.3
installing source package 'MYPACKAGE' ...
** R
** data
* moving datasets to lazyload DB
** preparing package for lazy loading
No man pages found in package 'MYPACKAGE'
** help
* installing help indices
** building package indices
** testing if installed package can be loaded
DONE (MYPACKAGE)
Edit:
Upon further investigation, it appears that this was caused by the fact that I have sub-directories within my R directory, which is not supported by default. A possible solution was located here which, however, I haven't yet tried out. I will report back with the outcome as soon as I am able to perform the tests.
I had the same error. roxygen2 was creating correctly the md files in the /man directory but they were not found at compilation time. I had the following error.
No man pages found in package
After a bit of time I found that in one of the R file I had a source statement
source("C:/Users/vaulot/Google Drive/Scripts/R library/dv_function_pr2.R")
My guess is that there was some code in the source file interfering with roxygen2.

Does R travis work on large data packages?

I seem to be running into a memory allocation issue when using R travis-ci on an R package that depends on a 90 Mb data package (i.e., that's where it gets its data from):
* installing *source* package ‘my_package’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in system2(file.path(R.home("bin"), "R"), c(if (nzchar(arch)) paste0("--arch=", :
cannot popen ' '/home/travis/R-bin/lib/R/bin/R' --no-save --slave 2>&1 < '/tmp/RtmpGLG3uQ/file2f65432e469d'', probable reason 'Cannot allocate memory'
* removing ‘/home/travis/R/Library/my_package’
Warning in q("no", status = 1, runLast = FALSE) :
system call failed: Cannot allocate memory
Error: Command failed (1)
Execution halted
The command "./travis-tool.sh github_package my_github_handle/my_package" failed and exited with 1 during .
Your build has been stopped.
Is it because travis-ci doesn't work with large data packages like this, or is it some other issue?
Related posts: https://github.com/travis-ci/travis-ci/issues/5713, https://github.com/travis-ci/travis-ci/issues/3656
Here is my travis.yml file
language: r
cache: packages
warnings_are_errors: true
sudo: required
before_install:
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
- chmod 755 ./travis-tool.sh
install:
- ./travis-tool.sh aptget_install r-cran-xml
- ./travis-tool.sh install_github hadley/devtools
- ./travis-tool.sh install_deps
- ./travis-tool.sh github_package my_github_handle/my_package
r_github_packages:
- my_github_handle/my_package
Note that both of my R packages (both the main R package and the data package it requires) are both on GitHub.
The later half of the travis.yml is not needed. Use:
language: r
cache: packages
warnings_are_errors: true
sudo: false
For other package dependencies use devtools' Remote: keyword in DESCRIPTION to specify repositories or opt to create your own repository and use it (Disclaimer: I wrote this article).
Travis images under this setup are restricted to having 4 GB of RAM. For more information on VM builds information see:
https://docs.travis-ci.com/user/ci-environment/#Virtualization-environments
This performs well with large data packages.

Packrat bootstrap doesn't find the packrat private library

I've built a Packrat project with several packages installed in the Packrat private library. I want to take the code and bring it, along with the Packrat library, to another system. The system I built the library in is Windows 7 running R 3.2.2 from Rstudio, and the system I'm moving it to is a Linux machine running R 3.1.2 from the command line. The version of packrat on the Windows machine is 0.4.6-1. Here is a rundown of the actions I took: on the Windows machine I ran
> packrat::bundle(include.lib=TRUE)
I took the resulting bundle and moved it over to the Linux system where I unzipped it using tar -zxvf packrat_bundle.tar.gz. I then entered the newly unzipped directory and started R. From there, packrat automatically bootstrapped (due to the line source("packrat/init.R") packrat placed in .Rprofile) and gave the following output
Packrat is not installed in the local library -- attempting to bootstrap an installation...
> Installing packrat into project private library:
- '/home/code/packrat/lib/x86_64-unknown-linux-gnu/3.1.2'
* installing *source* package âpackratâ ...
** package âpackratâ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (packrat)
> Attaching packrat
> Restoring library
Already up to date.
> Packrat bootstrap successfully completed. Entering packrat mode...
Updating system packages ('3.2.2' -> '3.1.2')
Packrat mode on. Using library in directory:
- "/home/code/packrat/lib"
Warning message:
In restore(restart = FALSE) :
The most recent snapshot was generated using R version 3.2.2
After this, the output from .libPaths() is
> .libPaths()
[1] "/home/code/packrat/lib/x86_64-unknown-linux-gnu/3.1.2"
[2] "/home/code/packrat/lib-ext"
[3] "/home/code/packrat/lib-R"
The issue is that the library that I created on the Windows machine is contained in the directory /home/code/packrat/lib/x86_64-w64-mingw32/3.2.2. As such, I have to add that to .libPaths to get the packrat library to work correctly. I don't mind having to change .libPaths by hand, but I feel strongly like I might be doing something incorrectly that is causing the problem.
Thanks for any help!
It turns out that the issue I was having was that I hadn't snapshotted packrat before attempting to move it to the other system. I solved the problem by first running packrat::snapshot() and then proceeding mostly as before.
I was under the mistaken assumption that by using packrat::bundle(include.lib=TRUE) that I could transfer my library that way. That's not the case, especially when the library needs to be moved to another system and rebuilt from source. Snapshotting first took care of the source rebuild, and packrat correctly bootstrapped.
My answer does not concern the question but I want to write here so maybe someone will read this and save so much time and frustration.
It has been 2 yrs since this question was posted. I used packrat package a year ago and still today i find it simply not usable. I tried to install dplyr and it takes 1 hr to install BH package ( dependency).
Much better working with checkpoint package. You have to specify 1 function
checkpoint("your_snapshot_date")
and you are ready to share your code as a reproducible example. Time to install dplyr: 3 min.

Building R package: "No man pages found in package"

My previously-functioning R package lllcrc recently broke, so I tweaked it, and now I'm having trouble building it again because it acts like it can't see my documentation files:
R CMD INSTALL lllcrc
* installing to library ‘/home/[...]/3.1’
* installing *source* package ‘lllcrc’ ...
** R
** preparing package for lazy loading
** help
No man pages found in package ‘lllcrc’
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (lllcrc)
This is totally weird because I definitely have a complete set of .Rd files in the man folder; in fact, I generated all of these using roxygen2, and all of this worked previously. The R CMD INSTALL even works enough so that the package actually installs and all of its examples run. But documentation is missing. Running ?foo just gives a "no documentation" message.
Another thing: R CMD Rd2pdf lllcrc generates the .pdf documentation as I would expect.
Any ideas?
I just had the same error message ... if you are using roxygen and RStudio then your problem might be the same. The reason became apparent when looking at "Configure build tools" in the "Build" drop-down menu: you need to tick the checkbox "Generate documentation with Roxygen". After that, everything worked.

Resources