-
Notifications
You must be signed in to change notification settings - Fork 53
Make script path available to R #122
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
Conversation
Hm, sure, if you really think you need it. It should not create too much trouble. Can we consider making it an opt-in? These littler reads one or two .rc files where you could flag it. Also, should we not call a path expansion on |
It's a little odd that the env var would be 'there' only in the script case but then again we do have the piped and expression cases and it is likely of less value there. |
I'm not sure what the variable would usefully contain in the pipe and expression cases. Path expansion isn't strictly required in my case but is worth having; I'll look into that and making the whole thing opt-in. |
Yes, maybe all we need is
and we may be good to go. |
setenv("LITTLER_SCRIPT_PATH", script_path, 1); | ||
else | ||
setenv("LITTLER_SCRIPT_PATH", argv[optind], 1); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I had not realized the extra work with realpath() here but well done! That is likely more useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realpath
is probably pretty universally available, but R checks for it so I thought I should play it safe. I'll add to the docs and changelog shortly (doing this between other stuff). Making it optional I'm not sure about - it would need a flag or an env var, I guess, neither of which feels ideal. I would hope it can be easily ignored where it's not helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate the clean configure.ac
work here.
Let's drop the optional. We guess we can bear the cost of setting an env.var.
Looks good. I may shorten the ChangeLog a wee bit (max of two lines per entry is a goal, remove two empty lines to group but overall this is ready to go. |
It can be helpful to know the path to the script being executed via a shebang line. This can be determined using
Rscript
via the--file=
argument, although it's a little clunky:But, as far as I can tell from the source and some experimentation,
r
doesn't pass this information throughargv
,commandArgs()
or the environment. This is a simple patch to set an environment variable containing the path, which should be unconditionally available by this point in the execution. The script path is then readily available:I'm happy to change the name of the variable or refactor if there's a better way to do this (or be told that there is already a mechanism for it!), but since it's a small addition I thought I'd just propose something.