return the name of source.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

return the name of source.

Nevil Amos
Is there a fuction that will allow me to retrun the filename for  a script
 from within that script.

fir instance

If I have a script "myscript.r":

FileName<-unknown.fucntion()
print(FileName)



and run it
source("myscript.r")

will return
"myscript.r"

Thanks

Nevil Amos

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: return the name of source.

Peter Dalgaard-2

On Aug 27, 2013, at 07:12 , nevil amos wrote:

> Is there a fuction that will allow me to retrun the filename for  a script
> from within that script.

Not a standard one, but you should be able to get at it via a bit of breaking and entering: sys.status() and friends (sys.calls, sys.frames) give you access to the evaluation frame of source() which contains a variable called "file".

-pd

>
> fir instance
>
> If I have a script "myscript.r":
>
> FileName<-unknown.fucntion()
> print(FileName)
>
>
>
> and run it
> source("myscript.r")
>
> will return
> "myscript.r"
>
> Thanks
>
> Nevil Amos
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: return the name of source.

Henrik Bengtsson-3
See findSourceTraceback() of R.utils.  /Henrik

On Mon, Aug 26, 2013 at 10:58 PM, peter dalgaard <[hidden email]> wrote:

>
> On Aug 27, 2013, at 07:12 , nevil amos wrote:
>
>> Is there a fuction that will allow me to retrun the filename for  a script
>> from within that script.
>
> Not a standard one, but you should be able to get at it via a bit of breaking and entering: sys.status() and friends (sys.calls, sys.frames) give you access to the evaluation frame of source() which contains a variable called "file".
>
> -pd
>
>>
>> fir instance
>>
>> If I have a script "myscript.r":
>>
>> FileName<-unknown.fucntion()
>> print(FileName)
>>
>>
>>
>> and run it
>> source("myscript.r")
>>
>> will return
>> "myscript.r"
>>
>> Thanks
>>
>> Nevil Amos
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: [hidden email]  Priv: [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: return the name of source.

Nevil Amos
Thanks

this does it:

script.name <- basename(sys.frame(1)$ofile)



On Tue, Aug 27, 2013 at 4:07 PM, Henrik Bengtsson <[hidden email]>wrote:

> See findSourceTraceback() of R.utils.  /Henrik
>
> On Mon, Aug 26, 2013 at 10:58 PM, peter dalgaard <[hidden email]> wrote:
> >
> > On Aug 27, 2013, at 07:12 , nevil amos wrote:
> >
> >> Is there a fuction that will allow me to retrun the filename for  a
> script
> >> from within that script.
> >
> > Not a standard one, but you should be able to get at it via a bit of
> breaking and entering: sys.status() and friends (sys.calls, sys.frames)
> give you access to the evaluation frame of source() which contains a
> variable called "file".
> >
> > -pd
> >
> >>
> >> fir instance
> >>
> >> If I have a script "myscript.r":
> >>
> >> FileName<-unknown.fucntion()
> >> print(FileName)
> >>
> >>
> >>
> >> and run it
> >> source("myscript.r")
> >>
> >> will return
> >> "myscript.r"
> >>
> >> Thanks
> >>
> >> Nevil Amos
> >>
> >>       [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> [hidden email] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > Peter Dalgaard, Professor,
> > Center for Statistics, Copenhagen Business School
> > Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> > Phone: (+45)38153501
> > Email: [hidden email]  Priv: [hidden email]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.