Packrat bootstrap doesn't find the packrat private library - r

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.

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.

R packrat snapshot: upgrading package gives "stale" errors

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
...

How can I access Windows COM objects in R v3?

Some time ago, you used to be able to install the rcom package in R to use COM scripting (eg, access to external programs.) Unfortunately, it seems to be discontinued:
Package ‘rcom’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
This depends on statconnDCOM, which nowadays restricts use, contrary
to the CRAN policy for a package with a FOSS licence. See
http://rcom.univie.ac.at/ and http://www.statconn.com/.
Following the archive and statconn links and installing one of the older versions in R version 3 gives the error:
“Error: package ‘rcom’ was built before R 3.0.0: please re-install
it”.
I am not very familiar with R, but there seems no way around this message - after all, it occurs when installing, so re-installing doesn't seem to be the answer. It appears as though rcom is simply not available for recent (3.0+) versions of R. I have also scanned the package list, although searching for "COM" there returns over a hundred results and it is possible I missed the right one when clicking through them.
How can I use the rcom package, or use COM from within R some other way?
(Note: I am asking this question on behalf of a colleague. I have no experience with R myself at all. Both of us, when searching for answers, could not find anything. I am sure that others are also using COM in the latest version of R, though!)
I looked at the rcom source code a few months ago. It seems I can get it to build and install OK on R3.0.1. Below is the procedure if it helps.
Get a checkout of the latest source code of rcom. I have rcom_2.2-5.tar.gz locally. I can google something at the following address, but I have no idea of the provenance, so up to you to check it is legit. http://cran.open-source-solution.org/web/packages/rcom/index.html
in R do install.packages('rscproxy')
install Rtools as per the instructions on the R web site (http://cran.r-project.org/bin/windows/Rtools),
open a Windows command prompt i.e. run "CMD"
go to the folder containing the 'rcom' folder, and at the command prompt:
set R="c:\Program Files\R\R-3.0.1\bin\i386\R.exe"
%R% CMD check --no-manual rcom
check it passes without too many complaints. Your call as to the --no-manual option (if you have MiKTeX installed you may remove it)
%R% CMD INSTALL rcom
should result in
installing to c:/Rlib/rcom/libs/i386
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
rcom requires a current version of statconnDCOM installed.
To install statconnDCOM type
installstatconnDCOM()
This will download and install the current version of statconnDCOM
You will need a working Internet connection
because installation needs to download a file.
* DONE (rcom)
in R:
library(rcom)
installstatconnDCOM()
I tried a comRegisterRegistry() ; comRegisterServer()
; x<-comGetObject("Excel.Application") but I get a NULL for x. I am not a user of rcom so while it all seems to compile fine; it may just not work anymore.
If you happen to need to access .NET code, a viable option (and yes I have a vested interest in mentioning it) may be the rClr package.
Hope this helps; I'd be interested to hear how you go.
This really should be a comment, but I don't have enough rep points yet to leave one.
I found that the above steps did not work for me, but the answer posted by Lisa Ann on this question, RExcel in R 3.0.x, did solve my problem installing rcom. Since you need rcom to run RExcel, the initial steps to install RExcel cover installing rcom on newer versions of R (such as 3.0.2).
Specifically, following the advice on statconn's wiki, http://homepage.univie.ac.at/erich.neuwirth/php/rcomwiki/doku.php?id=wiki:how_to_install
You also need to follow these instructions if you upgrade R, i.e. you install a new >release of R after you have installed RExcel.
Download the statconn DCOM server and execute the program you downloaded
Start R as administrator (on Windows 7 you need to right-click the R icon and click the >corresponding item)
In R, run the following commands (you must start R as administrator to do this)
install.packages(c("rscproxy","rcom"),repos="http://rcom.univie.ac.at/download",lib=.Library)
library(rcom)
comRegisterRegistry()
Now you have rcom installed, [instructions for installing RExcel follow...]
New versions of rcom and rscproxy (also for current versions of R) are available from a different repository. Just use http://rcom.univie.ac.at/download as the R repository to install from and you can download and install binary versions of statconn packages from there.
Hope this helps!

Is the bigvis package for R not available for R version 3.0.1?

I'm developing an app designed to handle big data and was having problems graphing the data in a useful way because of the sheer amount of plot points. My initial idea was to create a little algorithm that, based on the size of the data, divides the data points into about 30 subsets and takes the average of all the points in these subsets (what are the faults of this implementation by the way)?
Then I learned about bigVis, which does a lot of the big data representation for you, and I really want to try this library out.
I have a problem installing it. I've done:
>install_github("devtools")
>install.packages("bigVis")
Warning in install.packages :
package ‘bigVis’ is not available (for R version 3.0.1)
I've also done:
>install_github("devtools")
>devtools::install_github("bigvis")
* installing *source* package 'bigvis' ...
** libs
*** arch - i386
ERROR: compilation failed for package 'bigvis'
* removing 'C:/Program Files/R/R-3.0.1/library/bigvis'
Error: Command failed (1)
Does anyone know what this error is?
Thanks
assuming you've got Rtools.exe installed, here are the steps to get bigvis installed if it still does not work. you need a 64-bit compiler in order to run the Rcpp package, one of the dependencies of bigvis
in R, confirm g++ isn't installed (or isn't 64-bit)
Sys.which( "g++" )
download mingw-w64 - http://sourceforge.net/projects/mingw-w64/ (Since the mingw-w64 project on sourceforge.net is moving to mingw-w64.org i suggest to use mingw-w64.org)
when the mingw-w64 installer pops up, be sure to change the architecture row from i686 to x86_64 then let it install
in the windows start menu search bar, type environment and an option edit the system environment variables should pop up. click it.
edit your PATH and add a semicolon plus the folder name of the bin directory of the mingw-w64 program that you just installed. for me, it was ;C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\bin but this will change for future versions
close & re-open R and Sys.which('g++') should now indicate the mingw-x64 directory
Sys.which('g++')
"C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\G__~1.EXE"
devtools:::install_github("hadley/bigvis") should now complete successfully
This works for me, using R v 3.0.1 on Windows 7.
Directly download the current package from GitHub:
download.file("https://github.com/hadley/bigvis/archive/master.zip", destfile = "bigvis.zip")
Unzip it, just so that we leave nothing to chance (though you could use the .zip itself):
unzip("bigvis.zip")
and install from source:
install.packages("bigvis-master", repos = NULL, type = "source")`

problem when installing RTextTools for R

I was trying to install RTextTools package for R, but failed. Here is the output from the screen
> > install.packages("RTextTools")
Warning in install.packages("RTextTools") :
argument 'lib' is missing: using 'C:\Users\datamining\Documents/R/win-library/2.10'
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘RTextTools’ is not available
What's the reason for this problem, and how to fix it? Thanks.
There are two distinct, but related, issues:
You are running version 2.10 of R which is two years old. CRAN supports only the current version with pre-built binaries. You could try installing from source.
RTextTools, as can be seen on its CRAN page also requires at least R version 2.13.
So in short: you should upgrade.
I have resolved the issue. I have Download RTextTools From Given Link.

https://cran.r-project.org/src/contrib/Archive/RTextTools/
and copy RTextTools_1.4.2.tar.gz file in project root folder then run this command in project folder in terminal
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
After running this command I receive below error
"ERROR: dependencies ‘SparseM’, ‘randomForest’, ‘tree’, ‘e1071’, ‘ipred’, ‘caTools’, ‘maxent’, ‘glmnet’, ‘tau’ are not available for package ‘RTextTools’".
Now install each dependencies from RStudio or RConsole (Any Editor used by you) by simply running this code.
install.packages("caTools").
Install all 9 required packages One By One (In My Case it was 9 Packages Dependencies required by RTextTools) all packages will be installed except 'maxent'.
Now download maxent from the given link.
https://cran.r-project.org/src/contrib/Archive/maxent/.
and copy maxent_1.3.3.1.tar file in project folder then run this command in project folder in terminal.
"R CMD INSTALL maxent_1.3.3.1.tar"
Now For RTextTools Run this command again in Terminal.
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
All is done Now..
But the Last Step is
Load the RTextTools using.
library(RTextTools)
You will see one more Error: Load SparseM Now Loading SparseM use code below.
library(SparseM)
and in the last Load RTextTools
library(RTextTools)
RTextTools is dependent on a number of packages, most of which require R 2.13+. You should always keep R updated to the latest version, since each update contains numerous bug fixes and performance enhancements.
If you can't install packages from repository or the packages are not available anymore, just follow this steps:
Install.packages("devtools")
check -- library("devtools")
install_github("cran/maxent")
install_github("cran/RTextTools")

Resources