[R] Genuine relative paths with R

Olivier GIVAUDAN o||v|er_g|v@ud@n @end|ng |rom hotm@||@com
Thu Oct 11 01:53:41 CEST 2018

Yes, I am aware that both '__FILE__' and 'SAS_EXECFILENAME' are macro variables. I don't know how the VBA 'Application.ThisWorkbook.Path' VBA or PHP '__DIR__' (or '__FILE__') work.

And yes, indeed, until now I didn't even realise that this simple find-and-replace solution of "mine" is actually the basic job of a preprocessor when it expands macro variables, thank you!

A macro language in R, yes, I think it would be useful, at least for this function. If nothing simpler is available, of course...
De : Peter Claussen <dakotajudo using mac.com>
Envoy� : mercredi 10 octobre 2018 23:29
� : Olivier GIVAUDAN
Cc : Duncan Murdoch; Jeff Newmiller; r-help using r-project.org
Objet : Re: [R] Genuine relative paths with R

If I�m following all this correctly, it seems your criticism is that R doesn�t provide a run-time function that is equivalent to a compile-time macro. You do realize that __FILE__ is not part of the C programming language - it�s a predefined variable recognized by the cpp - the C preprocessor program. Similarly, SAS_EXECFILENAME is a predefined variable that can be recognized by the SAS macro processor, but has no meaning in the SAS language itself.

So, to go back to your original post:
1.  Either create a variable "ScriptPath" in the first lines of each of my R scripts and run a batch (or shell, etc.) to replace every single occurrence of "ScriptPath <-" by "ScriptPath <- [Absolute path of the R script]" in all the R scripts located in the folder (and possibly subfolders) of the batch file.

This is what a macro processor does. Are you asking for a macro language in R?


On Oct 10, 2018, at 6:11 PM, Olivier GIVAUDAN <olivier_givaudan using hotmail.com<mailto:olivier_givaudan using hotmail.com>> wrote:

It is not wrong to claim that R currently doesn't have a function returning the path of the R file where this same function was invoked.

'getwd()' is indeed not equivalent to VBA 'Application.ThisWorkbook.Path' or C macro '__FILE__' or SAS %sysget(SAS_EXECFILENAME), etc.

	[[alternative HTML version deleted]]

More information about the R-help mailing list