Closed klmr closed 1 year ago
Correction:
.Rprofile
is loaded viasys.source
.
Not true. 😢 In reality it’s loaded via R_LoadProfile
in the C code in main/main.c
. In turn, this dispatches to R_ReplFile
. Furthermore, that function gets a FILE*
and doesn’t actually know the filename. Inside the context of the .Rprofile
evaluation there is no stack trace, no marker from where the expressions being evaluated are read, and no other indication (as far as I can see) that we are currently inside an R profile file.
I’m currently stumped how to support this without changes to the actual R source code.
Furthermore, the same function R_LoadProfile
is used to load the site file, the system profile and a Tcl/Tk frontend source file, although I think we could ignore this.
In addition, sometimes the .Rprofile
file will be sourced via source
or sys.source
and we need to catch those cases because this will happen in cases where the user dispatches to a different .Rprofile
file from a local one (e.g. ‘callr’ does this). So, really, we should just generically handle source
and sys.source
, but this doesn’t happen with the original .Rprofile
, as it were.
… furthermore, .First
is executed afterwards, in a slightly different context, but should probably be treated by ‘box’ as if it was executed inside the profile file which defined it; and unfortunately we don’t know which one that was. Unless keep.source
was active, we have simply no way of finding out which.
Conclusion: currently impossible to implement in R. 😞
Please describe your feature request
.Rprofile
is loaded viasys.source
. Extend thepath_test_hooks
to add handling forsys.source
by inspecting the call stack, finding the nearestsys.source
call frame (if any) and extracting thefile
value from it.This check probably needs to have medium priority because it needs to happen before checks for RStudio etc.
Unfortunately this might cause substantial slowdowns for every
box::use
andbox::file
call. On the flip side the current check is already quite slow and should be optimised further, if possible.