-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JooYoung Seo
committed
Sep 6, 2019
1 parent
9a3615b
commit ef39fdd
Showing
1 changed file
with
68 additions
and
66 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,84 @@ | ||
# getting some useful batch files for processing R scripts and Rmarkdown files. | ||
# Windows users only | ||
|
||
MakeBatch = | ||
function(file = NULL) { | ||
if (interactive()) { | ||
MakeBatch = function(file = NULL) { | ||
if (interactive()) { | ||
if (.Platform$OS.type == "windows") { | ||
RHome = gsub("/", "\\\\", Sys.getenv("R_HOME")) | ||
if (is.null(file)) { | ||
# write a batch file for processing R scripts | ||
cat(paste0(RHome, "\\bin\\R.exe CMD BATCH --vanilla --quiet %1\n"), | ||
file = "RBatch.bat") | ||
message("RBatch.bat created successfully.") | ||
# write a batch file for processing a specific R markdown file | ||
cat(paste0(RHome, | ||
"\\bin\\RScript.exe --vanilla -e \"rmarkdown::render('%1')\"\n"), | ||
file = "RmdBatch.bat") | ||
message("RmdBatch.bat created successfully.") | ||
# write a batch file for processing all R markdown files | ||
cat(paste0(RHome, '\\bin\\Rscript.exe --vanilla -e "BrailleR::ProcessAllRmd()"\n'), | ||
file = "ProcessAllRmd.bat") | ||
message("ProcessAllRmd.bat created successfully.") | ||
# write a batch file for processing all markdown files | ||
cat(paste0(RHome, '\\bin\\Rscript.exe --vanilla -e "BrailleR::ProcessAllMd()"\n'), | ||
file = "ProcessAllMd.bat") | ||
message("ProcessAllMd.bat created successfully.") | ||
message( | ||
"These files need to be moved to a folder that is on your system path.") | ||
# write a file to show the system path settings | ||
cat(Sys.getenv("PATH"), file = "path.txt") | ||
message("These details are saved in path.txt for reference.") | ||
# write a test Rmd file | ||
cat("# a test file | ||
RHome = gsub("/", "\\\\", Sys.getenv("R_HOME")) | ||
if (is.null(file)) { | ||
|
||
# Assign path depending upon system architecture | ||
R_architecture <- Sys.info()[["machine"]] | ||
|
||
if (R_architecture == "x86-64") { | ||
R_path <- paste0(RHome, "\\bin\\x64\\") | ||
} else { | ||
R_path <- paste0(RHome, "\\bin\\") | ||
} | ||
|
||
# write a batch file for processing R scripts | ||
cat(paste0("@echo off\n", R_path, "R.exe CMD BATCH --vanilla --quiet %1\nstart %~dp1\\%~n1.Rout\n"), | ||
file = "RBatch.bat") | ||
message("RBatch.bat created successfully.") | ||
# write a batch file for processing a specific R markdown file | ||
cat(paste0("@echo off\nSET \"string=%1\"\n\n", R_path, "RScript.exe --vanilla -e \"lapply(rmarkdown::render('%string:\\=/%', output_format = 'all'), utils::browseURL)\"\n"), | ||
file = "RmdBatch.bat") | ||
message("RmdBatch.bat created successfully.") | ||
# write a batch file for processing all R markdown files | ||
cat(paste0("@echo off\n", R_path, "Rscript.exe --vanilla -e \"BrailleR::ProcessAllRmd()\"\n"), | ||
file = "ProcessAllRmd.bat") | ||
message("ProcessAllRmd.bat created successfully.") | ||
# write a batch file for processing all markdown files | ||
cat(paste0("@echo off\n", R_path, "Rscript.exe --vanilla -e \"BrailleR::ProcessAllMd()\"\n"), | ||
file = "ProcessAllMd.bat") | ||
message("ProcessAllMd.bat created successfully.") | ||
message("These files need to be moved to a folder that is on your system path.") | ||
# write a file to show the system path settings | ||
cat(Sys.getenv("PATH"), file = "path.txt") | ||
message("These details are saved in path.txt for reference.") | ||
# write a test Rmd file | ||
cat("# a test file | ||
## created by the BrailleR package | ||
My R version is `r version$major`.`r version$minor` and is being used to create this test file | ||
It will then be used to process the test file later once the necessary actions are taken in Windows Explorer. \n", | ||
file = "test1.Rmd") | ||
message("test1.Rmd created successfully.") | ||
MakeBatch("test1.Rmd") | ||
# write a test R script | ||
cat("# a test file | ||
It will then be used to process the test file later once the necessary actions are taken in Windows Explorer. \n", | ||
file = "test1.Rmd") | ||
message("test1.Rmd created successfully.") | ||
MakeBatch("test1.Rmd") | ||
# write a test R script | ||
cat("# a test file | ||
## created by the BrailleR package | ||
MySample=sample(100, 10) | ||
MySample | ||
mean(MySample) \n", | ||
file = "test2.R") | ||
cat("test2.R created successfully.\n") | ||
MakeBatch("test2.R") | ||
message( | ||
"Consult the help page for guidance on using these files in Windows Explorer.") | ||
} else { | ||
if (!file.exists(file)) | ||
warning(paste0('The specified file "', file, | ||
'" does not currently exist.\n')) | ||
FullFile = unlist(strsplit(file, split = ".", fixed = TRUE)) | ||
if (endsWith(file, ".R") | endsWith(file, ".r")) { | ||
# write a batch file for processing the R script | ||
cat(paste0(RHome, "\\bin\\R.exe CMD BATCH --vanilla --quiet ", | ||
FullFile[1], ".R\n"), | ||
file = paste0(FullFile[1], ".bat")) | ||
message(FullFile[1], ".bat created successfully.") | ||
mean(MySample) \n", | ||
file = "test2.R") | ||
cat("test2.R created successfully.\n") | ||
MakeBatch("test2.R") | ||
message("Consult the help page for guidance on using these files in Windows Explorer.") | ||
} else { | ||
if (!file.exists(file)) | ||
warning(paste0("The specified file \"", file, "\" does not currently exist.\n")) | ||
FullFile = unlist(strsplit(file, split = ".", fixed = TRUE)) | ||
if (endsWith(file, ".R") | endsWith(file, ".r")) { | ||
# write a batch file for processing the R script | ||
cat(paste0(RHome, "\\bin\\R.exe CMD BATCH --vanilla --quiet ", | ||
FullFile[1], ".R\n"), file = paste0(FullFile[1], ".bat")) | ||
message(FullFile[1], ".bat created successfully.") | ||
} | ||
if (endsWith(file, ".Rmd") | endsWith(file, ".rmd")) { | ||
|
||
# write a batch file for processing the R markdown file | ||
cat(paste0(RHome, "\\bin\\RScript.exe -e \"rmarkdown::render('", | ||
FullFile[1], ".Rmd')\"\n"), file = paste0(FullFile[1], ".bat")) | ||
message(FullFile[1], ".bat created successfully.") | ||
} | ||
} | ||
if (endsWith(file, ".Rmd") | endsWith(file, ".rmd")) { | ||
|
||
# write a batch file for processing the R markdown file | ||
cat(paste0(RHome, "\\bin\\RScript.exe -e \"rmarkdown::render('", | ||
FullFile[1], ".Rmd')\"\n"), | ||
file = paste0(FullFile[1], ".bat")) | ||
message(FullFile[1], ".bat created successfully.") | ||
} | ||
} | ||
} else { | ||
warning( | ||
"This function is for users running R under the Windows operating system.\n") | ||
warning("This function is for users running R under the Windows operating system.\n") | ||
} | ||
} else { | ||
} else { | ||
warning("This function is meant for use in interactive mode only.\n") | ||
} | ||
return(invisible(NULL)) | ||
} | ||
return(invisible(NULL)) | ||
} |
ef39fdd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajrgodfrey, please read the notes above.