Skip to content

Instantly share code, notes, and snippets.

@ccowens
Created September 5, 2018 21:44
Show Gist options
  • Save ccowens/946a3a3a2c24f529c6b3d2fc5ee6d2e4 to your computer and use it in GitHub Desktop.
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
#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