Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running Rscript via rig subcommand #199

Open
klmr opened this issue Nov 1, 2023 · 4 comments
Open

Allow running Rscript via rig subcommand #199

klmr opened this issue Nov 1, 2023 · 4 comments
Labels
feature a feature request or enhancement

Comments

@klmr
Copy link

klmr commented Nov 1, 2023

Rig has a subcommand rig run to run a specific version of R with arguments.

It would be great if there was a similar way of running Rscript, e.g.:

rig run --script -r devel ‹file›
rig script -r devel -e ‹expr›
@gaborcsardi
Copy link
Member

gaborcsardi commented Nov 1, 2023

@klmr Thanks! Since you probably know this already, can you remind me what the benefits of Rscript are over R -f?

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Nov 1, 2023
@klmr
Copy link
Author

klmr commented Nov 1, 2023

The benefit/difference is that Rscript doesn’t echo the executed code, so it behaves like most other mainstream scripting language interpreters in non-interactive (perl, ruby, python …) in this regard.

I don’t know why R -f does this, and maybe there are use-cases. But for self-contained command line utilities this is pretty much never the expected behaviour (notably, it makes programmatic processing of the output much harder).

Cf.:

$ R -e 'cat("hello\n")'
> cat("hello
+ ")
hello

$ Rscript -e 'cat("hello\n")'
hellp

@gaborcsardi
Copy link
Member

OK, makes sense. I guess you'd need to suppress the echo explicitly:

❯ R -s -q -e 'cat("hello\n")'
hello

But we can have (probably)

rig run --script -r devel ‹file›

@klmr
Copy link
Author

klmr commented Nov 1, 2023

Regarding the -q option: the most important use-case for Rscript is probably in shebang lines of executable scripts: (for reasons I don’t understand) shebang lines limit the number of arguments you can pass portably, so you couldn’t have a shebang line that specifies the arguments -q -f (actually you can’t even pass a single argument).

But that’s of course irrelevant for usage via rig run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants