rmarkdown::run does not accept file path with quotes

Hallo everybody!

Probably a basic problem, but I could not find the answer anywhere. I am getting started with rmarkdown with runtime: shiny, but when I click on Run Document I get the Error

Error: unexpected symbol in "rmarkdown::run('C:/Luca\'s Documents/Statistics/Use of R/Lucas R study.Rmd', shiny_args = list(launch.browser = FALSE), auto_reload = FALSE, dir = 'C:/Luca's"
Execution halted

The problem is clearly the quote in the path (folder "Luca's Documents"), because if I move the file to another path all works. However, for several reasons I cannot work in another path, nor can I rename the path.
Interestingly, I see that the first quote is escaped automatically with \, but the second one in the argument to dir is not. That's why the execution stops.
Is there a way to get RStudio and markdown to work with paths with special characters, or to compel RStudio to also escape that second occurrence of the backquote?

Thank you!

Hi, Luca

path <- "'C:/Luca\'s Documents/Statistics/Use of R/Lucas R study.Rmd', shiny_args = list(launch.browser = FALSE), auto_reload = FALSE, dir = 'C:/Luca\'s"

print(path)
#> [1] "'C:/Luca's Documents/Statistics/Use of R/Lucas R study.Rmd', shiny_args = list(launch.browser = FALSE), auto_reload = FALSE, dir = 'C:/Luca's"

Created on 2019-05-27 by the reprex package (v0.3.0)

I'm not on Win and don't have your Rmd file, but if you look at how I've defined path, you'll see that I escaped \' in the dir argument, and if the print function is ok with it, knit should be, too.

Hi @technocrat, thank you!

Indeed, I also thought of forcing RStudio to properly escape the quote in the dir argument as well.
I tried defining a new dir, with the path properly written, in the first line of the script:

This works until I get another error - RStudio signals that, when I then click on "Run Document", the document is interpreted as a normal markdown document, not a shiny one.
I know why this happens: I learned here that shiny documents require the very first line of the script to contain the YAML header, otherwise the document will not be recognized as shiny.

Therefore, possible solutions are:

  • Forcing RStudio to read a pre-defined path with properly escaped special symbols in a way different from specifying it in the first line of the script (my preference);
  • Forcing shiny to work even with a first line not starting with a YAML (probably not possible).

I really cannot believe that nobody in the world uses the buttons in RStudio with file paths containing quotes!

Any suggestions? :slight_smile:

I'm dull, rather than shiny, but I would bet that YAML is non-negotiable. The only thing that comes to mind is here() if you have the file in your working directory.

If that doesn't work and no one else weighs in, I suggest reposting with a headline such as "What is best way to deal with path special characters in shiny"

Good luck!

Thanks @technocrat!

Since I never could get here() to work properly in my workflow, I ended up simply removing special characters from my folder tree. This was a huge life step and quite a pity, because I had been using "Luca's documents" since my first laptop when I was a teenager, and because this required re-organizing an automatic cloud backup I had been using for 10 years. But I agree that the next step is indeed getting here() to work rather than touching upon path definition in shiny, I think.

1 Like

I feel your pain. Changes like that are like switching hands in a sport. Condolences and good luck!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.