I have seen the question asked here from 2018. I'm wondering if there is a better answer today.
Our work computers are bedeviled by an entire IT security department that seems to exist to make them useless. We are allowed to run R 3.6.3 (4.x hasn't been approved yet). We cannot connect to CRAN from behind the corporate firewall. In the past that meant we took our laptops home to install packages. But now we have a download monitor that blocks CRAN downloads even when we're on our own wi-fi.
I was attempting to get around this by downloading the package .zip files on a personal machine, transferring them via CD, and then installing with repos=NULL. I used this code
getPackages <- function(packs){
packages <- unlist(
tools::package_dependencies(packs, available.packages(),
which=c("Depends", "Imports"), recursive=TRUE)
)
packages <- union(packs, packages)
packages
}
to get the dependencies for the package I wanted and downloaded them all with download.packages()
. I was trying to install tidyquant
so it turned out there were 113 dependencies.
But of course this downloads the latest version of all 113 packages, several of which it turned out were incompatible with R 3.6.3.
The solution I referenced above suggested finding a compatible version and then using
install_version("<package name>",
version = "<version number>",
repos = "http://cran.us.r-project.org")
But that would involve manually searching all 113 dependencies...plus I'm looking for a general purpose solution that I can share with the ~10 other people in my office that all have this issue now.
I'm hoping that since 2018 a better solution may have presented itself?
Update: Based on answers below I tried
tmp <- tempfile()
dir.create(tmp)
checkpoint::checkpoint(snapshot_date = "2020-04-01",
r_version = "3.6.3",
checkpoint_location = tmp,
scan_now = FALSE)
packages <- getPackages(c("tidyquant"))
download.packages(packages, destdir="C:\\Users\\jerem\\Downloads\\tidyquant", type="win.binary")
I get
Running create_checkpoint in the home directory may result
in checkpointing very many packages. Continue? (Y/n) Y
Creating checkpoint directory C:/Users/jerem/AppData/Local/Temp/Rtmpa2YEjU/file1efc6daf58e3/.checkpoint/2020-04-01/lib/x86_64-w64-mingw32/3.6.3
Using checkpoint directory C:/Users/jerem/AppData/Local/Temp/Rtmpa2YEjU/file1efc6daf58e3/.checkpoint/2020-04-01/lib/x86_64-w64-mingw32/3.6.3
Warning messages:
1: In create_checkpoint(snapshot_date, r_version, checkpoint_location, :
Specified R version not the same as current R version
2: In use_checkpoint(snapshot_date, r_version, checkpoint_location, :
Specified R version not the same as current R version
>
> packages <- getPackages(c("tidyquant"))
>
> download.packages(packages, destdir="C:\\Users\\jerem\\Downloads\\tidyquant", type="win.binary")
Warning: unable to access index for repository https://mran.microsoft.com/snapshot/2020-04-01/bin/windows/contrib/4.1:
cannot open URL 'https://mran.microsoft.com/snapshot/2020-04-01/bin/windows/contrib/4.1/PACKAGES'
Warning in download.packages(packages, destdir = "C:\\Users\\jerem\\Downloads\\tidyquant", :
no package ‘tidyquant’ at the repositories
Warning in download.packages(packages, destdir = "C:\\Users\\jerem\\Downloads\\tidyquant", :
no package ‘lubridate’ at the repositories
Warning in download.packages(packages, destdir = "C:\\Users\\jerem\\Downloads\\tidyquant", :
no package ‘PerformanceAnalytics’ at the repositories
And the "no package" warnings go on for all 113 dependencies.
I think the key here is
Warning: unable to access index for repository https://mran.microsoft.com/snapshot/2020-04-01/bin/windows/contrib/4.1:
Obviously there wouldn't be a 4.1 repository in April 2020. I assume it's trying that since the machine is running 4.1. So it seems we're tantalizingly close....
If it helps
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
system code page: 65001
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2 checkpoint_1.0.2