Created
September 5, 2018 21:44
-
-
Save ccowens/946a3a3a2c24f529c6b3d2fc5ee6d2e4 to your computer and use it in GitHub Desktop.
#change library(pckg) copied lines to if(!require(pckg)) {install.packages("pckg"); library(pckg)} lines in clipboard
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
#change library(pckg) copied lines to if(!require(pckg)) {install.packages("pckg"); library(pckg)} lines in clipboard | |
writeLines( | |
unlist( | |
lapply(readLines(file("clipboard")), | |
function(x) { | |
x <- substr(x, nchar("library(")+1, nchar(x)-1) | |
paste0("if(!require(",x,")) {install.packages(\"",x,"\"); library(",x,")}") } | |
)), file("clipboard")) | |
closeAllConnections() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment