Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

best way to locally capture and restore packages #8

Closed
benmarwick opened this issue Jan 29, 2015 · 3 comments
Closed

best way to locally capture and restore packages #8

benmarwick opened this issue Jan 29, 2015 · 3 comments

Comments

@benmarwick
Copy link
Contributor

Thanks for joining @cboettig and I at cboettig/nonparametric-bayes#55 (comment) I wonder if you could advise me if I've got the right idea here:

I've got your package on my computer with this...

# needed to build the vignette
source("http://bioconductor.org/biocLite.R")
biocLite("BiocStyle")

# get the package from github and build the vingette, takes a minute or two
devtools::install_github("gmbecker/gRAN", build_vignettes = TRUE)

Now I'm doing some work, for example...

# do some work, for example with these packages...
library(MASS)
library(gender)
# ... do various analyses...

Now I want to capture my working environment by getting the packages currently used by my R session for this analysis and store them locally where I can have a compendium that includes my R scripts and a nearby directory with the versions of the packages used in those scripts. Am I on the right track with this next bit?

# gets the CRAN packages of the packages in currently attached and stores
# them locally. You'd do this at the end of an analysis when all the libraries
# you've used are loaded in the environment, ie. at the end of a Rmd file. 

path <- getwd() # where the packages will be downloaded to
my_local_repo <- "my_local_repo" # name of local repo
session_packages <- sessionRepo(sessionInfo(), repo_dir = path, dir = path, 
                        libloc = path,
                        stoponfail = FALSE, # skip github pkgs, not supported
                        replace = TRUE, # update previous virtual repository
                        name = "my_local_repo") # give it a name

# Now we have a local repository of packages that match the ones used
# for this analysis. Let's say we archive all of this somewhere, ready to return to 
# some time later. 

Time passes... we want to go back to that work we did earlier and install those local old packages into our current env...

# Now I want I want to draw on this local repository
# to load the same libraries that were used to generate the archive. We don't
# want to download them again because we might not have good internet access,
# or we're not sure they'll still be online, etc. So let's install packages 
# from this local repository that we just created in the previous line.
# Assuming we are in the project directory, and that we have saved
# `session_packages` somewhere when we did the earlier work...

# get the paths to each individual package
session_packages_paths  <- list.files(session_packages, full.names = TRUE)

# make a directory for the local library
my_local_library <- paste0(getwd(), "/my_local_library")

# install the packages to that local library, have to respond with 'y'
# at the prompts to create a personal library:

install.packages(session_packages_paths, 
                 repos = NULL, 
                 type =" source", 
                 lib = my_local_library)

# inspect the current session
sessionInfo()
# inspect the local custom library
library(lib.loc = my_local_library)

I'm not sure what's going on here, do I now have those old local packages installed in my current env, is that correct? Is this the right way about it, or is there a simpler way?

thanks!

@gmbecker
Copy link
Owner

gmbecker commented Feb 2, 2015

@benmarwick Apologies for not responding sooner. switchr and GRANBase are not focused on capturing package sources locally for installation later. In fact, the manifest design is specifically intended to not require that (though I admit it does require internet access, which other solutions such as packrat do not).

The model here is to publish a manifest, e.g. as a gist, and then you or others install from that manifest as necessary.

That said, what you want should be possible with makeRepo from the API_refactor branch in this repository (which I hope to merge as a major update to master sometime this week), via the code:

man = libManifest() # get our manifest of installed pkgs
param = RepoBuildParam(basedir = <dir>, install_test = FALSE, check_test = FALSE)
repo = GRANRepository(manifest = man, param = param)
makeRepo(repo)

That currently won't work due to a bug writing this up discovered, but I will track that down and fix that shortly. Once it works, that will create a fully local package repository containing the contents of the manifest.

Thanks for your interest, and I will keep you abreast of bug squashing, etc via comments here.

@benmarwick
Copy link
Contributor Author

Thanks very much for looking over my example and the further explanation, that's very helpful. I look forward to testing the makeRepo function when it gets to the master branch.

@gmbecker
Copy link
Owner

gmbecker commented Feb 9, 2015

@benmarwick Apologies for the delay. The branch (API_refactor) that I
referred to in my previous comments has just been merged into master. Feel
free try the solution/code I suggested before at your convenience and let
me know if anything doesn't work.

Thanks,
~G

On Thu, Feb 5, 2015 at 12:35 PM, Ben Marwick notifications@github.com
wrote:

Thanks very much for looking over my example and the further explanation,
that's very helpful. I look forward to testing the makeRepo function when
it gets to the master branch.


Reply to this email directly or view it on GitHub
#8 (comment).

Gabriel Becker, PhD
Computational Biologist
Bioinformatics and Computational Biology
Genentech, Inc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants