Last active
December 11, 2020 01:05
-
-
Save josherrickson/ad5aae978240e23b21724e474673dbb5 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
echo "i <- rownames(installed.packages())" > __tmp__.R | |
grep -oh --include=\*.{Rmd,R} -r * -e "\(library\|require\)([A-Za-z0-9.]\+)" | \ | |
sed 's_library(_"_' | \ | |
sed 's_require(_"_' | \ | |
sed 's_)_",_' | sort | uniq | \ | |
perl -p -e 's/\n/ /' | \ | |
sed 's_^_new <- c(_' | \ | |
sed 's_, *$_)_' \ | |
>> __tmp__.R | |
echo >> __tmp__.R | |
echo "install.packages(new[!new %in% i])" >> __tmp__.R | |
# For debugging | |
#cat __tmp__.R | |
R --quiet -e "source('__tmp__.R')" | |
rm __tmp__.R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some updates: Fix to missing newline (L14); reduce length of input string (L8).