Re: [R-SIG-Mac] Retrieving Script Path in R.app

2021-10-10 Thread Duncan Murdoch

See https://stackoverflow.com/a/47045368/2554330 for a risky-looking method.

I think the non-RStudio method is equivalent to this function:

this.path <- function() {
  sys.frame(-5)$srcfile
}

which works for me using Cmd-E, but of course it doesn't work using 
Cmd-Enter, because that doesn't call source().


My conclusion would be to use RStudio rather than the R.app editor.  I 
prefer R.app for interactive use, but not at all for code development.


Duncan Murdoch


On 09/10/2021 11:23 p.m., Andrew Simmons wrote:

Hello,


I'd like to programmatically retrieve the path of the currently open script
in R.app.
Something like, if I had written:

this.path()

within a script that was open in R.app, and I ran that line with
Command+Enter,
I'd like it to return the path of the script.
It seems like this should be possible since Command+E runs the following:

source("/absolute/path/to/file")

so R.app knows the path of the open script, but I was unable to find
anything that would retrieve it on my own. First, I tried looking through
the environment 'as.environment("tools:RGUI")', but I didn't find anything
that looked like what I was looking for. Second, I tried comparing the
functions available in the base packages between Windows and macOS, and
while there are a few functions available for macOS that are not for
Windows, none of them looked like what I was looking for.
Any help will be greatly appreciated, thank you!


Regards,
 Andrew Simmons

[[alternative HTML version deleted]]

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac



___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] Retrieving Script Path in R.app

2021-10-10 Thread Andrew Simmons
getSrcDirectory is fine, but it only works when using 'source' with
'keep.source = TRUE', so it severely limits how I can run my scripts.

I've made a function / / package called this.path which returns the path of
the executing script, and right now it works from Rscript, when using
source, when running in RStudio, and when running from Rgui on Windows, but
not in R.app on macOS. Similar idea to getSrcDirectory, but you can run it
any way with or without keep.source


On Sun, Oct 10, 2021, 11:14 Ben Tupper  wrote:

> Hi,
>
> Would ?getSrcDirectory help?
>
> Ben
>
> On Sat, Oct 9, 2021 at 11:23 PM Andrew Simmons  wrote:
> >
> > Hello,
> >
> >
> > I'd like to programmatically retrieve the path of the currently open
> script
> > in R.app.
> > Something like, if I had written:
> >
> > this.path()
> >
> > within a script that was open in R.app, and I ran that line with
> > Command+Enter,
> > I'd like it to return the path of the script.
> > It seems like this should be possible since Command+E runs the following:
> >
> > source("/absolute/path/to/file")
> >
> > so R.app knows the path of the open script, but I was unable to find
> > anything that would retrieve it on my own. First, I tried looking through
> > the environment 'as.environment("tools:RGUI")', but I didn't find
> anything
> > that looked like what I was looking for. Second, I tried comparing the
> > functions available in the base packages between Windows and macOS, and
> > while there are a few functions available for macOS that are not for
> > Windows, none of them looked like what I was looking for.
> > Any help will be greatly appreciated, thank you!
> >
> >
> > Regards,
> > Andrew Simmons
> >
> > [[alternative HTML version deleted]]
> >
> > ___
> > R-SIG-Mac mailing list
> > R-SIG-Mac@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>
>
>
> --
> Ben Tupper (he/him)
> Bigelow Laboratory for Ocean Science
> East Boothbay, Maine
> http://www.bigelow.org/
> https://eco.bigelow.org
>

[[alternative HTML version deleted]]

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] Retrieving Script Path in R.app

2021-10-10 Thread Ben Tupper
Hi,

Would ?getSrcDirectory help?

Ben

On Sat, Oct 9, 2021 at 11:23 PM Andrew Simmons  wrote:
>
> Hello,
>
>
> I'd like to programmatically retrieve the path of the currently open script
> in R.app.
> Something like, if I had written:
>
> this.path()
>
> within a script that was open in R.app, and I ran that line with
> Command+Enter,
> I'd like it to return the path of the script.
> It seems like this should be possible since Command+E runs the following:
>
> source("/absolute/path/to/file")
>
> so R.app knows the path of the open script, but I was unable to find
> anything that would retrieve it on my own. First, I tried looking through
> the environment 'as.environment("tools:RGUI")', but I didn't find anything
> that looked like what I was looking for. Second, I tried comparing the
> functions available in the base packages between Windows and macOS, and
> while there are a few functions available for macOS that are not for
> Windows, none of them looked like what I was looking for.
> Any help will be greatly appreciated, thank you!
>
>
> Regards,
> Andrew Simmons
>
> [[alternative HTML version deleted]]
>
> ___
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



-- 
Ben Tupper (he/him)
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac


Re: [R-SIG-Mac] Retrieving Script Path in R.app

2021-10-10 Thread Thomas Hopper
You may want to look at the “here” package. 

Sent from my iPhone

> On Oct 9, 2021, at 23:23, Andrew Simmons  wrote:
> 
> Hello,
> 
> 
> I'd like to programmatically retrieve the path of the currently open script
> in R.app.
> Something like, if I had written:
> 
> this.path()
> 
> within a script that was open in R.app, and I ran that line with
> Command+Enter,
> I'd like it to return the path of the script.
> It seems like this should be possible since Command+E runs the following:
> 
> source("/absolute/path/to/file")
> 
> so R.app knows the path of the open script, but I was unable to find
> anything that would retrieve it on my own. First, I tried looking through
> the environment 'as.environment("tools:RGUI")', but I didn't find anything
> that looked like what I was looking for. Second, I tried comparing the
> functions available in the base packages between Windows and macOS, and
> while there are a few functions available for macOS that are not for
> Windows, none of them looked like what I was looking for.
> Any help will be greatly appreciated, thank you!
> 
> 
> Regards,
>Andrew Simmons
> 
>[[alternative HTML version deleted]]
> 
> ___
> R-SIG-Mac mailing list
> R-SIG-Mac@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

___
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac