Quantcast

__FILE__ for R

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

__FILE__ for R

hadley wickham
I've often missed the ability to get the directory of the currently
running script.  It's actually been possible for a while:

FILE <- (function() {
  attr(body(sys.function()), "srcfile")
})()

thanks to Duncan's recent changes to file parsing.  This is pretty
useful for sourcing in files relative to the current script, rather
than the working directory.

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: __FILE__ for R

hadley wickham
Sorry, that should be:

FILE <- (function() {
  attr(body(sys.function()), "srcfile")
})()$filename

Hadley

On Fri, Apr 4, 2008 at 10:34 AM, hadley wickham <[hidden email]> wrote:

> I've often missed the ability to get the directory of the currently
>  running script.  It's actually been possible for a while:
>
>  FILE <- (function() {
>   attr(body(sys.function()), "srcfile")
>  })()
>
>  thanks to Duncan's recent changes to file parsing.  This is pretty
>  useful for sourcing in files relative to the current script, rather
>  than the working directory.
>
>  Hadley
>
>  --
>  http://had.co.nz/
>



--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: __FILE__ for R

Gabor Grothendieck
Although its kludgy this previously (and still works) too:

parent.frame(2)$ofile

if called from top level within a sourced file.

On Fri, Apr 4, 2008 at 11:50 AM, hadley wickham <[hidden email]> wrote:

> Sorry, that should be:
>
> FILE <- (function() {
>  attr(body(sys.function()), "srcfile")
> })()$filename
>
> Hadley
>
>
> On Fri, Apr 4, 2008 at 10:34 AM, hadley wickham <[hidden email]> wrote:
> > I've often missed the ability to get the directory of the currently
> >  running script.  It's actually been possible for a while:
> >
> >  FILE <- (function() {
> >   attr(body(sys.function()), "srcfile")
> >  })()
> >
> >  thanks to Duncan's recent changes to file parsing.  This is pretty
> >  useful for sourcing in files relative to the current script, rather
> >  than the working directory.
> >
> >  Hadley
> >
> >  --
> >  http://had.co.nz/
> >
>
>
>
> --
> http://had.co.nz/
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Loading...