Re: [R] Is a .R script file name available inside the script?

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Sat 19 Mar 2005 - 14:00:23 EST

Darren Weber <darrenleeweber <at> gmail.com> writes:

:
: Hi,
:
: if we have a file called Rscript.R that contains the following, for example:
:
: x <- 1:100
: outfile = "Rscript.Rout"
: sink(outfile)
: print(x)
:
: and then we run
:
: >> source("Rscript.R")
:
: we get an output file called Rscript.Rout - great!
:
: Is there an internal variable, something like .Platform, that holds
: the script name when it is being executed? I would like to use that
: variable to define the output file name.
:

In R 2.0.1 try putting this in a file and sourcing it.

script.description <- function() eval.parent(quote(file), n = 3) print(basename(script.description()))

If you are using R 2.1.0 (devel) then use this instead:

script.description <- function()

	showConnections() [as.character(eval.parent(quote(file), n = 3)), 
		"description"]

print((basename(script.description())))

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Mar 19 14:09:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:51 EST