find_dangerous_terms <- function(scriptPath = "rfordummies/inst/scripts"){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
if(!file.exists(htmlPath)) stop("html path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
for (scr in scripts){
message(scr)
txt <- readLines(scr)
idx <- grep("[(quit)(install.packages)]", txt)
cat(txt[idx])
}
}
# stitch_dummies()
find_dangerous_terms()
find_dangerous_terms <- function(scriptPath = "rfordummies/inst/scripts"){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
for (scr in scripts){
message(scr)
txt <- readLines(scr)
idx <- grep("[(quit)(install.packages)]", txt)
cat(txt[idx])
}
}
# stitch_dummies()
find_dangerous_terms()
find_dangerous_terms <- function(scriptPath = "rfordummies/inst/scripts"){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
for (scr in scripts){
message(scr)
txt <- scan(scr)
idx <- grep("[(quit)(install.packages)]", txt)
cat(txt[idx])
}
}
# stitch_dummies()
find_dangerous_terms()
find_dangerous_terms <- function(scriptPath = "rfordummies/inst/scripts"){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
for (scr in scripts){
message(scr)
txt <- scan(scr, what="character")
idx <- grep("[(quit)(install.packages)]", txt)
cat(txt[idx])
}
}
# stitch_dummies()
find_dangerous_terms()
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
?regexp
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
idx <- sapply(iris[, -5], function(x)head(order(x, decreasing=TRUE), 2))
idx
idx <- lapply(iris[, -5], function(x)head(order(x, decreasing=TRUE), 2))
idx
library(plyr)
ldply(iris[, -5], summarize, function(x)head(order(x, decreasing=TRUE), 2)
)
ldply(iris[, -5], summarize, function(x)head(order(x, decreasing=TRUE), 2))
llply(iris[, -5], summarize, function(x)head(order(x, decreasing=TRUE), 2))
llply(iris[, -5], function(x)head(order(x, decreasing=TRUE), 2))
llply(iris[, -5], function(x)x[head(order(x, decreasing=TRUE), 2)])
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
txt <- scan("rfordummies/inst/scripts/ch12.r", what="character", sep="\n", quiet=TRUE)
head(txt)
grep("^(! *# *).*(quit\\()|(q\\(\\))|(install.packages)", txt, perl=TRUE)
idx <- grep("^(! *# *).*(quit\\()|(q\\(\\))|(install.packages)", txt, perl=TRUE)
txt[idx]
idx <- grep("^!( *# *).*(quit\\()|(q\\(\\))|(install.packages)", txt, perl=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
library(knitr)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
noRunFunctions <- c("quit", "q", "readClipboard", "install.packages")
paste(noRunFunctions, "\\(")
paste0(noRunFunctions, "\\(")
noRunFunctions <- c("quit", "q", "readClipboard", "install.packages")
tmp <- paste0("(", noRunFunctions, "\\(", ")")
tmp
noRunFunctions <- c("quit", "q", "readClipboard", "install.packages")
tmp <- paste0("(", noRunFunctions, "\\(", ")", collapse="|")
tmp
noRunFunctions <- c("quit", "q", "readClipboard", "install.packages")
ptn <- sprintf("^!( *#* *).*%s", paste0("(", noRunFunctions, "\\(", ")", collapse="|"))
ptn
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
source('~/.active-rstudio-document', echo=TRUE)
getwd()
stitch_dummies(scriptPath = "rfordummies/inst/scripts/2-clean", htmlPath="rfordummies/inst/scripts/3-html")
stitch_dummies <- function(scriptPath, htmlPath=){
require(knitr)
if(!file.exists(scriptPath)) stop("script path doesn't exist")
if(!file.exists(htmlPath)) stop("html path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
wd <- getwd()
on.exit(setwd(wd))
setwd(htmlPath)
for (scr in scripts){
message(scr)
stitch_rhtml(scr)
}
}
stitch_dummies(scriptPath = "rfordummies/inst/scripts/2-clean", htmlPath="rfordummies/inst/scripts/3-html")
stitch_dummies <- function(scriptPath, htmlPath){
require(knitr)
if(!file.exists(scriptPath)) stop("script path doesn't exist")
if(!file.exists(htmlPath)) stop("html path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
wd <- getwd()
on.exit(setwd(wd))
setwd(htmlPath)
for (scr in scripts){
message(scr)
stitch_rhtml(scr)
}
}
stitch_dummies(scriptPath = "rfordummies/inst/scripts/2-clean", htmlPath="rfordummies/inst/scripts/3-html")
source('~/GitHub/rfordummies/rfordummies/inst/cleanscripts.R', echo=TRUE)
clean_all_scripts <- function(scriptPath, outPath, comment=TRUE, message=FALSE){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
clean <- lapply(scripts, clean_script, message=message)
ret <- sapply(seq_along(scripts), function(i){
newFile <- file.path(outPath, basename(scripts[i]))
#     message(newFile)
txt <- paste(clean[i], collapse="\n")
writeLines(txt, con=newFile)
newFile
})
invisible(ret)
}
clean_all_scripts(scriptPath = "rfordummies/inst/scripts/1-orig", outPath = "rfordummies/inst/scripts/2-clean")
clean_all_scripts <- function(scriptPath, outPath, comment=TRUE, message=FALSE){
if(!file.exists(scriptPath)) stop("script path doesn't exist")
scripts <- normalizePath(list.files(scriptPath, pattern=".r$", full.names = TRUE))
clean <- lapply(scripts, clean_script, message=message)
ret <- sapply(seq_along(scripts), function(i){
newFile <- file.path(outPath, basename(scripts[i]))
#     message(newFile)
txt <- paste(clean[[i]], collapse="\n")
writeLines(txt, con=newFile)
newFile
})
invisible(ret)
}
clean_all_scripts(scriptPath = "rfordummies/inst/scripts/1-orig", outPath = "rfordummies/inst/scripts/2-clean")
source('~/GitHub/rfordummies/rfordummies/inst/cleanscripts.R', echo=TRUE)
source('~/GitHub/rfordummies/rfordummies/inst/cleanscripts.R', echo=TRUE)
