Last active
September 19, 2023 19:20
-
-
Save otsaloma/f3b8f61a39bf81df0bcc0e5fd80e9ad1 to your computer and use it in GitHub Desktop.
Project specific snapshot dependencies for R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local({ | |
| # https://packagemanager.posit.co/client/#/repos/cran/setup | |
| url = "https://packagemanager.posit.co/cran/2023-09-01" | |
| r_version = gsub("\\.\\d+$", "", as.character(getRversion())) | |
| cran_version = rev(unlist(strsplit(url, "/+")))[1] | |
| dir = sprintf("~/.R/library/%s-%s", r_version, cran_version) | |
| message(sprintf("Using %s", url)) | |
| message(sprintf("Using %s", dir)) | |
| options(repos=url) | |
| if (!dir.exists(dir)) | |
| dir.create(dir, recursive=TRUE) | |
| .libPaths(dir) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local({ | |
| # Source any possible project-specific .init.R first | |
| # as it might set .libPaths for custom dependencies. | |
| # https://gist.github.com/otsaloma/f3b8f61a39bf81df0bcc0e5fd80e9ad1 | |
| components = unlist(strsplit(getwd(), "/")) | |
| for (i in length(components):1) { | |
| args = as.list(c(components[1:i], ".init.R")) | |
| path = do.call(file.path, args) | |
| if (file.exists(path)) { | |
| source(path) | |
| break | |
| } | |
| } | |
| }) | |
| # Make sure your later .Rprofile doesn't overwrite the above, | |
| # e.g. if you want to set default repos, use the following form. | |
| # options(repos=getOption("repos", "https://cran.rstudio.com/")) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use RStudio's snapshots as Microsoft's MRAN has been unreliable for a while now.