You are not logged in.

#1 2018-06-10 01:22:14

nicholas
Member
Registered: 2012-07-22
Posts: 39

[SOLVED] Rscript fails to run script with spaces in filepath in BASH

While using the following "hello world" R script saved to a file named "/tmp/Example Directory/myRScript.R",

#!/usr/bin/env Rscript
print("This certainly doesn't work!")

if I set it to executable and try to run it I get the following error

$ /tmp/Example\ Directory/myRScript.R 
Fatal error: cannot open file '/tmp/Example': No such file or directory

Removing the space in the path fixes the issue.

Cutting out the middle-man of the shebang, Rscript is at a loss with quotes, too:

$ Rscript "/tmp/Example Directory/myRScript.R"
Fatal error: cannot open file '/tmp/Example': No such file or directory

Strangely, running with literally any argument fixes it, though

$ Rscript --pleaseParseMyFilePathCorrectly /tmp/Example\ Directory/myRScript.R 
WARNING: unknown option '--pleaseParseMyFilePathCorrectly'

[1] "oh NOW it works"

Am I perhaps missing something trivial here? Anyone else seen this?

Last edited by nicholas (2018-06-10 17:02:23)

Offline

#2 2018-06-10 01:43:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [SOLVED] Rscript fails to run script with spaces in filepath in BASH

It seems it's intentional, though absolutely absurd:

$ sed -n 129,135p Rscript.c
    /* When executed via '#!' on most systems, argv_[1] will include multiple
       arguments. These arguments will be those provided directly on the line
       starting with '#!'.

       argv_[1] is split here into individual arguments assuming any space or
       tab is a separator - no quoting is supported
    */

I'd file an upstream bug report if you can find a way to be sufficiently tactful when informing them that that is completely absurd, that's not how positional parameters work.  The second argument (argv[1]) is the file name and nothing else.

Clearly there help output doesn't even match what they are doing:

$ Rscript --help
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]
...
'file' may contain spaces but not shell metacharacters

Last edited by Trilby (2018-06-10 01:52:33)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-06-10 13:34:44

nicholas
Member
Registered: 2012-07-22
Posts: 39

Re: [SOLVED] Rscript fails to run script with spaces in filepath in BASH

Wow... Ok. Thanks for the intel.

I did a quick Google but can't easily find where the upstream *is*.
I'll happily file a bug, though, if I find em.

Offline

#4 2018-06-10 14:54:27

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] Rscript fails to run script with spaces in filepath in BASH

https://www.archlinux.org/packages/extra/x86_64/r/ links their homepage: https://www.r-project.org/

But on their "Reporting Bugs" page they state:

r-project wrote:

If your bug is in the language, though, or the Core-supported packages, you should submit your report to R’s Bugzilla.
NOTE: due to abuse by spammers, since 2016-07-09 only “members” (including all who have previously submitted bugs) can submit new bugs on R’s Bugzilla. For now, either post (e-mail) your bug report to R-devel or ask an R Core member to add you manually to R’s Bugzilla members.

So, uh, good luck with that.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2018-06-10 14:54:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [SOLVED] Rscript fails to run script with spaces in filepath in BASH

$ R --help
...
Report bugs at <https://bugs.R-project.org>.

I was also going to wish "good luck" for other reasons: I've stopped reporting bugs to any GNU projects.  They persistently try to reinvent the wheel and make it square ignoring all standards of unix/linux/POSIX systems, and when it's highlighted that they have a ridiculous amount of code to work around a non-issue they just get confused for a while, then angry, then they go into denial and seem to completely lose track of what the issue was in the first place.

Last edited by Trilby (2018-06-10 14:57:11)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2018-06-10 17:02:00

nicholas
Member
Registered: 2012-07-22
Posts: 39

Re: [SOLVED] Rscript fails to run script with spaces in filepath in BASH

Thank you both for the links and geez. Noted.
I'll put it on the back-log to do for a day that I'm feeling like spending time fighting for it.

For now this ugly work-around does the trick

#!/usr/bin/Rscript --

Thread can be closed.

Last edited by nicholas (2018-06-10 17:02:45)

Offline

Board footer

Powered by FluxBB