Giter Club home page Giter Club logo

pkgsnap's Introduction

pkgsnap

Backup and Restore Certain CRAN Package Versions

Project Status: Active - The project has reached a stable, usable state and is being actively developed. Linux Build Status Windows Build status Coverage Status CRAN RStudio mirror downloads

Create a snapshot of your installed CRAN packages with 'snap', and then use 'restore' on another system to recreate exactly the same environment.

Installation

devtools::install_github("mangothecat/pkgsnap")

Usage

library(pkgsnap)

For this experiment we create a new library directory, and install some packages there. We will then remove this directory entirely, and recreate it using pkgsnap.

lib_dir <- tempfile()
dir.create(lib_dir)

We make this new library directory the default:

.libPaths(lib_dir)

The new library directory is currently empty:

installed.packages(lib_dir)[, c("Package", "Version")]
#>      Package Version

Let's install some packages here. Note that the dependencies of these packages will be also installed.

install.packages(c("testthat", "pkgconfig"))
#> Installing packages into '/private/var/folders/ws/7rmdm_cn2pd8l1c3lqyycv0c0000gn/T/RtmpOssfTB/file1003d2f2dd0b1'
#> (as 'lib' is unspecified)
#> also installing the dependency 'praise'
#> 
#> Package which is only available in source form, and may need
#>   compilation of C/C++/Fortran: 'testthat'
#> 
#> The downloaded binary packages are in
#> 	/var/folders/ws/7rmdm_cn2pd8l1c3lqyycv0c0000gn/T//RtmpOssfTB/downloaded_packages
#> installing the source packages 'praise', 'testthat'
installed.packages(lib_dir)[, c("Package", "Version")]
#>           Package     Version 
#> pkgconfig "pkgconfig" "2.0.0" 
#> praise    "praise"    "1.0.0" 
#> testthat  "testthat"  "0.11.0"

We will now create a snapshot, and then scrap the temporary package library.

snapshot <- tempfile()
snap(to = snapshot)
read.csv(snapshot)[1:5,]
#>         Package Version Source Link
#> 1             R   3.3.0      R   NA
#> 2     pkgconfig   2.0.0   cran   NA
#> 3        praise   1.0.0   cran   NA
#> 4      testthat  0.11.0   cran   NA
#> 5 BiocInstaller  1.21.3   bioc   NA
unlink(lib_dir, recursive = TRUE)

Create a new package library.

new_lib_dir <- tempfile()
dir.create(new_lib_dir)
.libPaths(new_lib_dir)

Finally, recreate the same set of package versions, in a new package library.

restore(snapshot)
#> Downloading
#>   pkgconfig_2.0.0.tgz...  done.
#>   praise_1.0.0.tgz...   praise_1.0.0.tgz...   praise_1.0.0.tar.gz...  done.
#>   testthat_0.11.0.tgz...   testthat_0.11.0.tgz...   testthat_0.11.0.tar.gz...  done.
#>   BiocInstaller_1.21.3.tgz...  done.
#>   covr_1.2.0.tgz...   covr_1.2.0.tgz...   covr_1.2.0.tar.gz...  done.
#>   crayon_1.3.1.tgz...  done.
#>   curl_0.9.5.tgz...   curl_0.9.5.tgz...   curl_0.9.5.tar.gz...   curl_0.9.5.tar.gz...  done.
#>   devtools_1.10.0.tgz...   devtools_1.10.0.tgz...   devtools_1.10.0.tar.gz...  done.
#>   digest_0.6.9.tgz...   digest_0.6.9.tgz...   digest_0.6.9.tar.gz...  done.
#>   git2r_0.13.1.tgz...  done.
#>   htmltools_0.3.tgz...   htmltools_0.3.tgz...   htmltools_0.3.tar.gz...  done.
#>   httr_1.1.0.tgz...   httr_1.1.0.tgz...   httr_1.1.0.tar.gz...  done.
#>   jsonlite_0.9.19.tgz...   jsonlite_0.9.19.tgz...   jsonlite_0.9.19.tar.gz...  done.
#>   lazyeval_0.1.10.tgz...   lazyeval_0.1.10.tgz...   lazyeval_0.1.10.tar.gz...  done.
#>   magrittr_1.5.tgz...   magrittr_1.5.tgz...   magrittr_1.5.tar.gz...  done.
#>   memoise_1.0.0.tgz...   memoise_1.0.0.tgz...   memoise_1.0.0.tar.gz...  done.
#>   mime_0.4.tgz...  done.
#>   openssl_0.9.1.tgz...   openssl_0.9.1.tgz...   openssl_0.9.1.tar.gz...   openssl_0.9.1.tar.gz...  done.
#>   R6_2.1.2.tgz...   R6_2.1.2.tgz...   R6_2.1.2.tar.gz...  done.
#>   rex_1.0.1.tgz...   rex_1.0.1.tgz...   rex_1.0.1.tar.gz...  done.
#>   rstudioapi_0.5.tgz...  done.
#>   simplegraph_1.0.0.tgz...   simplegraph_1.0.0.tgz...   simplegraph_1.0.0.tar.gz...  done.
#>   whisker_0.3-2.tgz...  done.
#>   withr_1.0.1.tgz...   withr_1.0.1.tgz...   withr_1.0.1.tar.gz...  done.
#> Installing
#>   pkgconfig_2.0.0.tgz ... done.
#>   praise_1.0.0.tar.gz ... done.
#>   testthat_0.11.0.tar.gz ... done.
#>   BiocInstaller_1.21.3.tgz ... done.
#>   covr_1.2.0.tar.gz ... done.
#>   crayon_1.3.1.tgz ... done.
#>   curl_0.9.5.tar.gz ... done.
#>   devtools_1.10.0.tar.gz ... done.
#>   digest_0.6.9.tar.gz ... done.
#>   git2r_0.13.1.tgz ... done.
#>   htmltools_0.3.tar.gz ... done.
#>   httr_1.1.0.tar.gz ... done.
#>   jsonlite_0.9.19.tar.gz ... done.
#>   lazyeval_0.1.10.tar.gz ... done.
#>   magrittr_1.5.tar.gz ... done.
#>   memoise_1.0.0.tar.gz ... done.
#>   mime_0.4.tgz ... done.
#>   openssl_0.9.1.tar.gz ... done.
#>   R6_2.1.2.tar.gz ... done.
#>   rex_1.0.1.tar.gz ... done.
#>   rstudioapi_0.5.tgz ... done.
#>   simplegraph_1.0.0.tar.gz ... done.
#>   whisker_0.3-2.tgz ... done.
#>   withr_1.0.1.tar.gz ... done.
installed.packages(new_lib_dir)[, c("Package", "Version")]
#>               Package         Version 
#> BiocInstaller "BiocInstaller" "1.21.3"
#> covr          "covr"          "1.2.0" 
#> crayon        "crayon"        "1.3.1" 
#> curl          "curl"          "0.9.5" 
#> devtools      "devtools"      "1.10.0"
#> digest        "digest"        "0.6.9" 
#> git2r         "git2r"         "0.13.1"
#> htmltools     "htmltools"     "0.3"   
#> httr          "httr"          "1.1.0" 
#> jsonlite      "jsonlite"      "0.9.19"
#> lazyeval      "lazyeval"      "0.1.10"
#> magrittr      "magrittr"      "1.5"   
#> memoise       "memoise"       "1.0.0" 
#> mime          "mime"          "0.4"   
#> openssl       "openssl"       "0.9.1" 
#> pkgconfig     "pkgconfig"     "2.0.0" 
#> praise        "praise"        "1.0.0" 
#> R6            "R6"            "2.1.2" 
#> rex           "rex"           "1.0.1" 
#> rstudioapi    "rstudioapi"    "0.5"   
#> simplegraph   "simplegraph"   "1.0.0" 
#> testthat      "testthat"      "0.11.0"
#> whisker       "whisker"       "0.3-2" 
#> withr         "withr"         "1.0.1"

License

MIT © Mango Solutions.

pkgsnap's People

Contributors

gaborcsardi avatar dougmet avatar cderv avatar wch avatar

Stargazers

Kelly Moran avatar Matt Dray avatar Jared Prins avatar Rob Gilmore avatar Shaurita Hutchins avatar John Blischak avatar Petr Bouchal avatar Omair A. Khan avatar Keyor avatar James Chang avatar Adam H. Sparks avatar Christopher Gandrud avatar Karthik Ram avatar  avatar Maëlle Salmon avatar Jonathan Carroll avatar Nicholas Tierney avatar Jemma Stachelek avatar Eduard Szöcs avatar Graeme Hickey avatar  avatar TJ Mahr avatar Ramnath Vaidyanathan avatar Andy Teucher avatar Zhian N. Kamvar avatar Jennifer (Jenny) Bryan avatar Matthew Henderson avatar Michał Bojanowski avatar Curtis Alexander avatar Jim Hester avatar Devin Pastoor avatar  avatar timelyportfolio avatar Thomas Sandmann avatar Peter Wildeford avatar Nathan Eastwood avatar Shinya Uryu avatar Francisco Rodriguez-Sanchez avatar Thomas J. Leeper avatar Ben Marwick avatar Sebastian Perez Saaibi avatar  avatar Tyler Rinker avatar

Watchers

 avatar timelyportfolio avatar James Cloos avatar James Chang avatar  avatar Nathan Eastwood avatar Andy Nicholls avatar  avatar

pkgsnap's Issues

Support for Windows

Currently get_description throws an error when restore is used on Windows platform.

cygwin warning:
  MS-DOS style path detected: C:\Users\CCAMPB~1\AppData\Local\Temp\Rtmp0EoEzi/assertthat_0.1.zip
  Preferred POSIX equivalent is: /cygdrive/c/Users/CCAMPB~1/AppData/Local/Temp/Rtmp0EoEzi/assertthat_0.1.zip
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
/usr/bin/tar: This does not look like a tar archive
/usr/bin/tar: Skipping to next header
/usr/bin/tar: assertthat/DESCRIPTION: Not found in archive
/usr/bin/tar: Exiting with failure status due to previous errors
Error in read.dcf(desc_file) : cannot open the connection
In addition: Warning messages:
1: running command 'tar.exe -xf "C:\Users\CCAMPB~1\AppData\Local\Temp\Rtmp0EoEzi/assertthat_0.1.zip" -C "C:/Users/CCAMPB~1/AppData/Local/Temp/Rtmp0EoEzi/file23d01e2e4547" "assertthat/DESCRIPTION"' had status 2 
2: In untar(package_file, files = paste(pkg, sep = "/", "DESCRIPTION"),  :
  ‘tar.exe -xf "C:\Users\CCAMPB~1\AppData\Local\Temp\Rtmp0EoEzi/assertthat_0.1.zip" -C "C:/Users/CCAMPB~1/AppData/Local/Temp/Rtmp0EoEzi/file23d01e2e4547" "assertthat/DESCRIPTION"’ returned error code 2
3: In read.dcf(desc_file) :
  cannot open compressed file 'C:\Users\CCAMPB~1\AppData\Local\Temp\Rtmp0EoEzi\file23d01e2e4547/assertthat/DESCRIPTION', probable reason 'No such file or directory'

cran mirror is fixed and can't be changed

I wanted to use this package for use with an in-house cran mirror.
However, pkgsnap:::default_cran_mirror is set to "http://cran.rstudio.com" inside the package.
Is this something that we could change ?

Should be easier if the package use getOption("repos")[["CRAN"]] if it exist or if we could select a cran mirror with an argument in restore.

I could try to work on something if you want.

README.md only works for a new installation of R

Following the example in README.md, it installs all packages you currently have installed on your system. This is because snap() is not explicit in where it should obtain the packages from by default, i.e. the user does not give it lib.loc for the installed.packages() function. Instead it uses the default NULL for all known trees (from ?installed.packages). Possibly a roxygen @param tag is needed in the ?snap helpfile to explain the recommended parameter?

Be careful checking R version with binary packages

With restore(needed_only=TRUE), pkgsnap compares the exact version of R to the version used to build each package. If a user is running R 3.3.1 and CRAN has binaries built on 3.3.2, then it will reinstall those packages built with 3.3.2, even though it's not really needed.

Broken on new macOS

Because package types are hard coded in cran_file you get:

> restore('test.csv')
 Error in cran_file(package, version, type = .Platform$pkgType, r_minor = r_minor,  : 
  Unknown package type: mac.binary.el-capitan see ?options. 

cran_file should really use contrib.url instead.

Record R version

snap: Record the version of the core R installation.

restore: Check R version, stop or warn depending on options.

Ignore pkgsnap package

Either ignore or at least handle separately. If the recorded version doesn't match the installed version it could give a warning, if it does match then it should be skipped.

Should it attempt to bootstrap itself if the installed version doesn't match the recorded? I would suggest that's a future feature.

pkgsnap with packages installed from github

Is there any way for pkgsnap to record and restore packages installed from github with specific SHA1 hashes? Also, can restore(snapshot) be invoked from within a R Markdown code chunk instead of from an R script that knits the document? (This is something that apparently does not work in the checkpoint package, so it would be nice if pkgsnap provided both this and the ability to restore from github). Thanks, Andrew.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.