Created
April 15, 2021 20:54
-
-
Save sellorm/20525aff669acafb975b7495b8f2066e to your computer and use it in GitHub Desktop.
Render an Rmarkdown document in the RStudio jobs pane.
This file contains hidden or 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
render_with_jobs <- function(){ | |
rstudioapi::verifyAvailable() | |
jobs_file <- tempfile(tmpdir = "/tmp", fileext = ".R") | |
rmd_to_render <- rstudioapi::selectFile(caption = "Choose an Rmd file...", | |
filter = "Rmd files (*.Rmd)") | |
if (is.null(rmd_to_render)){ | |
stop("You must choose an Rmd file to proceed!") | |
} | |
cat(paste0('rmarkdown::render("', rmd_to_render, '")'), file = jobs_file) | |
rstudioapi::jobRunScript(path = jobs_file, | |
name = basename(rmd_to_render), | |
workingDir = getwd()) | |
# Wait for 5 seconds so that the tmp file isn't deleted *before* the job | |
# submission is complete | |
Sys.sleep(5) | |
file.remove(jobs_file) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@NevilHopley I've only ever seen this happen if you have some piece of code using the Windows "C:\Users..." style paths instead of "C:/Users/..." somewhere in your code. The error you're getting specifically highlights '\U' as being the problem, so if there's somewhere in your code where you've typed in "C:\Users...", make sure to swap it with the other slashes and try it again.