1

Running my working R script in the windows command line (cmd) using Rscript results in a parsing error (premature EOF).

When I run the script in RStudio, it compiles and runs as expected.

I have read the Rscript page in R documentation, and I see that the problem must be due to spaces in my script itself, which probably make it into the cmd console somehow during parsing, but that's as far as I get.

Or should I have done something with the #! functionality mentioned therein?

I am trying to run it on cmd:

Rscript .\start_app.r

I am in the right working directory, and have set the folder containing Rscript in my environment.

The script is too long to share, and I am too inexperienced to give you the parts that make it break (otherwise I wouldn't be here), but it is full of functions, if statements and the like, that use curly brackets and are indented. I also often include empty rows (someteimes indented) for readability. It makes use of the shiny-package. An example could be:

islocal = nchar(Sys.getenv("LOCAL"))>1 | interactive()
if (islocal){
  source('../../path/app/variables/styling.R')

} else {
  source('./variables/styling.R')
}

As the example above, it also includes other R code called via source()

Can that somehow make it to the cmd line and be incorrectly compiled?

I get the following messages:

Error: parse error: premature EOF

                     (right here) ------^
Execution halted
Not enough memory resources are available to process this command.

(I guess the second message is an unrelated issue, but include it here just to be sure.)

  • Hi, without the full code it is hard to tell what causes it – Chelmy88 Aug 27 '19 at 09:41
  • 2
    I would first suggest you try doublequotes, **`"`**, instead of single, **`'`**, around your path strings. I will additionally suggest you take a look at [this question](https://stackoverflow.com/q/48544345), there may be something there which helps you out. – Compo Aug 27 '19 at 09:56
  • 2
    What about the memory issue in your error message ? And what about the encoding of your script ? Did you try to change this encoding ? – MrSmithGoesToWashington Aug 27 '19 at 10:23
  • Thanks for the suggestions. @MrSmithGoesToWashington it does turn out to have something to do with the encoding: https://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using#17177904 . Using "Save with Encoding -> ISO-8895-1 (System default)" solves the issue (even though running chcp in cmd returns codepage 65001, which corresponds with UTF-8) but breaks the code when I run in RStudio. If you want to post the suggestion as an answer I'd be happy to accept it. – Nibood_the_slightly_advanced Aug 27 '19 at 14:25

1 Answers1

0

As suggested in a comment, the solution was changing the encoding.

As mentionned by the requestor himself, Using "Save with Encoding -> ISO-8895-1 (System default)" solves the issue.