Last active
May 3, 2018 02:10
-
-
Save dongzhuoer/dd332dc13ef06ee4447f69aaacbdcb1a to your computer and use it in GitHub Desktop.
This script is used before `update.packages(ask = F)` on Travis CI R
This file contains 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
if (Sys.getenv('TRAVIS_OS_NAME') == 'linux') { | |
installed <- installed.packages() | |
recommended <- installed[mapply(identical, installed[ ,"Priority"], 'recommended'), 'Package'] | |
lapply(recommended, function(pkg){ | |
src = file.path(.Library, pkg); | |
desc = file.path(.libPaths()[1], pkg); | |
if (dir.exists(desc)) | |
unlink(src, T) | |
else { | |
dir.create(desc); | |
file.rename(src, desc); | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When building R package with Travis, we want to the dependency packages to be the latest and well cached.
Although
update.packages(ask = F)
is very convenient when you run in sudo mode, Travis only caches user library.After a awful afternoon, I come up with a solution:
Move recommended packages (system packages get updated along with R) to user library if they don't exist, then they can be cached. The next time, recommended packages in system library will be removed. (While there seem be a override rule, we still tend to avoid duplicate. Actually, Travis will get a warning when it just update the one in user library)