{"action":"created","issue":{"url":"https://api.github.com/repos/pbiecek/archivist/issues/251","repository_url":"https://api.github.com/repos/pbiecek/archivist","labels_url":"https://api.github.com/repos/pbiecek/archivist/issues/251/labels{/name}","comments_url":"https://api.github.com/repos/pbiecek/archivist/issues/251/comments","events_url":"https://api.github.com/repos/pbiecek/archivist/issues/251/events","html_url":"https://github.com/pbiecek/archivist/issues/251","id":134304568,"number":251,"title":"ainstall","user":{"login":"MarcinKosinski","id":6773454,"avatar_url":"https://avatars.githubusercontent.com/u/6773454?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcinKosinski","html_url":"https://github.com/MarcinKosinski","followers_url":"https://api.github.com/users/MarcinKosinski/followers","following_url":"https://api.github.com/users/MarcinKosinski/following{/other_user}","gists_url":"https://api.github.com/users/MarcinKosinski/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcinKosinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcinKosinski/subscriptions","organizations_url":"https://api.github.com/users/MarcinKosinski/orgs","repos_url":"https://api.github.com/users/MarcinKosinski/repos","events_url":"https://api.github.com/users/MarcinKosinski/events{/privacy}","received_events_url":"https://api.github.com/users/MarcinKosinski/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pbiecek/archivist/labels/functionality","name":"functionality","color":"fbca04"},{"url":"https://api.github.com/repos/pbiecek/archivist/labels/proposition","name":"proposition","color":"0098f0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-17T15:06:47Z","updated_at":"2016-02-28T15:25:22Z","closed_at":null,"body":"for a specific md5hash, `asession` gives packages and versions under which it was created, maybe one should create `ainstall` function that install specific versions of R packages with the usage of this package https://cran.r-project.org/web/packages/versions/index.html"},"comment":{"url":"https://api.github.com/repos/pbiecek/archivist/issues/comments/189891833","html_url":"https://github.com/pbiecek/archivist/issues/251#issuecomment-189891833","issue_url":"https://api.github.com/repos/pbiecek/archivist/issues/251","id":189891833,"user":{"login":"MarcinKosinski","id":6773454,"avatar_url":"https://avatars.githubusercontent.com/u/6773454?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcinKosinski","html_url":"https://github.com/MarcinKosinski","followers_url":"https://api.github.com/users/MarcinKosinski/followers","following_url":"https://api.github.com/users/MarcinKosinski/following{/other_user}","gists_url":"https://api.github.com/users/MarcinKosinski/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcinKosinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcinKosinski/subscriptions","organizations_url":"https://api.github.com/users/MarcinKosinski/orgs","repos_url":"https://api.github.com/users/MarcinKosinski/repos","events_url":"https://api.github.com/users/MarcinKosinski/events{/privacy}","received_events_url":"https://api.github.com/users/MarcinKosinski/received_events","type":"User","site_admin":false},"created_at":"2016-02-28T15:25:22Z","updated_at":"2016-02-28T15:25:22Z","body":"I went with devtools::install_version (but it does not support `lib` parameter passed to install.packages, so I also neededtouse `.libPaths()` :\r\n\r\ncheck this out\r\n\r\n````{R}\r\n# Recreate packages library for artifact\r\nMarcin Kosiński  \r\n27 lutego 2016  \r\n\r\n\r\n\r\n# Retrieve object created with archive-version of ggplot2\r\n\r\n\r\n```r\r\nlibrary(devtools)\r\ninstall.packages('ggplot2', repos = 'https://cran.rstudio.com/')\r\nlibrary(ggplot2)\r\ndevtools::session_info(pkgs = 'ggplot2')\r\n```\r\n\r\n\r\n```r\r\nadir <- 'adir'\r\ndir.create(adir)\r\n.libPaths(c(adir, .libPaths())) # lib argument in devtools does not work\r\ninstall.packages('devtools', repos = 'https://cran.rstudio.com/')\r\ndevtools::install_version('ggplot2', version = '1.0.1', lib = adir, repos = 'https://cran.rstudio.com/')\r\nlibrary(ggplot2, lib = adir)\r\ndevtools::session_info('ggplot2')\r\n```\r\n\r\n\r\n# arecreate()\r\n\r\n\r\n```r\r\nlibrary(archivist)\r\nsystem.file('graphGallery', package = 'archivist') -> archivist.dir\r\nsetLocalRepo(archivist.dir)\r\narecreate.dir <- 'arecreate.dir' \r\ndir.create('arecreate.dir')\r\n\r\narecreate <- function(md5hash = '600bda83cb840947976bd1ce3a11879d', lib, repos = 'https://cran.rstudio.com/' ){\r\n  \r\n  old_lib <- .libPaths()\r\n  new_lib <- .libPaths(lib)\r\n  \r\n  # probably local installations or GitHub packages\r\n  NOT_CRAN <- which(asession(md5hash)$packages[, '*'] == '*')\r\n  \r\n  CRAN_PKGS <- grep('CRAN',\r\n                    x = asession(md5hash)$packages[, 'source'])\r\n  GITHUB_PKGS <- grep('Github',\r\n                    x = asession(md5hash)$packages[, 'source'])\r\n  # reinstall CRAN packages\r\n  \r\n  sapply(setdiff(CRAN_PKGS, NOT_CRAN), function(package){\r\n    devtools::install_version(asession(md5hash)$packages[package, 'package'],\r\n                                 version = asession(md5hash)$packages[package, 'version'], \r\n                                 lib = lib, repos = repos )\r\n  })\r\n  # extract commits and names from parenthesis\r\n  gsub(\"[\\\\(\\\\)]\",\r\n       \"\", \r\n       regmatches(asession(md5hash)$packages[GITHUB_PKGS, 'source'],\r\n                  gregexpr(\"\\\\(.*?\\\\)\",\r\n                           asession(md5hash)$packages[GITHUB_PKGS, 'source'])\r\n                  )[[1]]\r\n       ) -> GITHUB_NAMES\r\n    # reinstall GitHub packages\r\n  devtools::install_github(GITHUB_NAMES, lib = lib)\r\n  .libPaths(old_lib)\r\n}\r\narecreate('600bda83cb840947976bd1ce3a11879d', lib = arecreate.dir)\r\n```\r\n\r\n\r\n```r\r\nknitr::kable(installed.packages(arecreate.dir))\r\n```\r\n\r\n\r\n````"}}