Skip to content

Instantly share code, notes, and snippets.

@sellorm
Created April 15, 2021 20:54
Show Gist options
  • Save sellorm/20525aff669acafb975b7495b8f2066e to your computer and use it in GitHub Desktop.
Save sellorm/20525aff669acafb975b7495b8f2066e to your computer and use it in GitHub Desktop.
Render an Rmarkdown document in the RStudio jobs pane.
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)
}
@sellorm
Copy link
Author

sellorm commented Sep 3, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment