Pete900 Pete900 - 1 month ago 17
R Question

Render rmarkdown from RStudio server to external drive

When working locally, I use the following to render rmarkdown documents:

rmarkdown::render(input = rmd.temp , output_dir = out.dir, output_file = out.name)


This gets my template doc
rmd.temp
, then renders the document to
out.dir
and names the file
out.name
.

I am trying to replicate on a RStudio server. When
out.dir
is a local directory the code works fine. However, when
out.dir
is a mapped directory to an external drive, I get the following error:

Error in replayPlot(x) :
could not open file'/...path..../figure-html/unnamed-chunk-2-1.png'


The link to the mapped drive works because I can use:

dir.create(out.dir)


and see the new folder appear. Any ideas why the rendering gets stuck?

Update

This is perhaps just a permission problem because I can't write a csv file either:

df <- data.frame(a=1:10)

setwd(out.dir)

write.csv(df, file = "df.csv")

Error in file(file, ifelse(append, "a", "w")) :
cannot open the connection


RStudio server is running on Ubuntu. I will open a new question on how to give RStudio folder permissions.

Answer

For anyone who has this problem, it can be fixed by adding this to the start of your script:

Sys.umask(mode="0000")

It was a permission problem. From the shell / command line, global permission was "0000" but from the RStudio console it was "0002", which produces -rw-r-- permissions for new files. The global permission can probably be changed for RStudio but this works.