On Fri, Jun 11, 2010 at 6:03 AM, Marcin Gomulka <mrgomel@gmail.com> wrote:

> AFAIK a script run through source() does not have any legit way to learn
> about it's own location.
>
> I need this to make sure that the script will find its datafiles after I
> move the whole directory. (The datafiles are in the same directory.)
>
> Here is a hack I invented to work around it:
>
> print(getwd())
> source_pathname  = get("ofile",envir = parent.frame())
> source_dirname = dirname(source_pathname )
> setwd(source_dirname)
> print(getwd())
>
> Question: Is there a better, cleaner way?
>
>
Hi,

I am using some thing like this to setup working directory:

##set working directory

pwd <- getwd()
if (!is.null(pwd)) {
                setwd(pwd)
        } else {
                print("Directory not found")
        }

Thanks & Rg
Mohan L

	[[alternative HTML version deleted]]

