0

I'm having an issue running some packages (including rmarkdown) in R. The problem is because I'm using Windows 10 and my HOME directory path includes spaces:

C:/Users/My Name/Documents

From doing a bit of research I realise that I need to change my HOME directory to something that doesn't have spaces; this is explained in this post, but not specifically how one should go about doing it.

I have two questions about this problem:

  1. How do I change the HOME directory to a path with no spaces?

  2. Will this cause issues when running other scripts, and if so is there a particular location on my C: drive that would be best to relocate HOME to?

An answer to this post suggests I should use Sys.setenv(R_USER="/my/desired/path"): would this force R to use a different HOME path? And if so, would I need to run this before running every script?

Edit: someone suggested looking at this post, but this doesn't quite get me where I want to be because I want to change the directory; so, re-setting the environment variable (by adding the .Renviron file to HOME) surely wouldn't work?

Many thanks!

Catherine Laing
  • 475
  • 6
  • 18
  • Possible duplicate of [R - Set environment variable permanently](https://stackoverflow.com/questions/49738564/r-set-environment-variable-permanently) – Benjamin Schwetz Mar 01 '19 at 12:03
  • 1
    rmarkdown should *not* have issues with spaces in the home directory (in fact, there’s no reason for *any* package to have issues with this — it’s incredibly sloppy programming). – Konrad Rudolph Mar 01 '19 at 12:07
  • This issue shows up every now and then (it doesn't stop me using markdown altogether) when I try to install certain packages for use in markdown, so it might not be rmarkdown itself. This time I've tried to run `devtools::install_github('yihui/tinytex')` and it won't work. – Catherine Laing Mar 01 '19 at 12:09
  • @CatherineLaing Are you sure you’re not misdiagnosing the issue? TinyTeX should work with spaces in path names. Why do you think spaces in the `HOME` path are the cause of the problems? – Konrad Rudolph Mar 01 '19 at 12:11
  • @KonradRudolph Whatever the problem is, it won't let me run TinyTeX - I get: `Downloading GitHub repo yihui/tinytex@master ERROR cannot change to directory 'C:\Users\My' The system cannot find the path specified. Error in run(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), : System command error` So as far as I can tell the problem lies in the path name of my `HOME` folder? – Catherine Laing Mar 01 '19 at 12:12
  • Use [shortPathName](https://stackoverflow.com/questions/23603074/working-directory-with-spaces-in-r/42528950#42528950) to get the path without spaces. – Stéphane Laurent Mar 01 '19 at 12:20
  • @StéphaneLaurent I don’t see how this would help here. – Konrad Rudolph Mar 01 '19 at 12:20
  • @KonradRudolph To set the path to install the package. `install.packages` does not work when there are white spaces in the path. – Stéphane Laurent Mar 01 '19 at 12:31
  • @StéphaneLaurent Huh. Is that a fact? That’s a pretty bad bug in R that should be fixed, shouldn’t it? Anyway, I’m assuming you’d then do `.libPaths(shortPathName(.libPaths()[1L]))`? – Konrad Rudolph Mar 01 '19 at 12:37
  • 1
    @KonradRudolph Yes this a fact. See https://stackoverflow.com/questions/52022233/install-packages-does-not-deal-with-whitespace-in-file-path or https://github.com/r-lib/devtools/issues/1467 I agree this should be fixed. – Stéphane Laurent Mar 01 '19 at 12:41
  • @StéphaneLaurent I'm using `install_github`; is there a way to specify the path with this? – Catherine Laing Mar 01 '19 at 12:45
  • @CatherineLaing Yes. Try `install_github(......, lib = shortPathName(.libPaths()[1]))`. – Stéphane Laurent Mar 01 '19 at 12:55
  • @StéphaneLaurent Ah no that doesn't work - I get exactly the same error as above. – Catherine Laing Mar 01 '19 at 13:09
  • @CatherineLaing Looks like the problem is the folder for the download. Normally this is a temporary directory. Why do you get when you do `tempdir()` ? Are there white spaces ? – Stéphane Laurent Mar 01 '19 at 13:14
  • @StéphaneLaurent No white spaces there: `"C:\\Users\\NAME~1\\AppData\\Local\\Temp\\RtmpWcbIH0"` – Catherine Laing Mar 01 '19 at 13:34

0 Answers0