[R] Strange behaviour of setwd/getwd
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Nov 2 19:14:45 CET 2012
On 02/11/2012 12:57 PM, Markus Holotta wrote:
> I've found the following strange behaviour R (RStudio) which has been
> confirmed by another user in RGui.
>
>
> Inside a script I want to set two variables:
>
> default.wd = getwd()
> tmp.wd = setwd(choose.dir())
>
> After choosing tmp.wd the value of default.wd is shown in Workspace, but
> getwd() is giving back the correct string of tmp.wd.
> Is there a workaround for the problem?
>
It's not clear what the problem is from your post. As the help page
says, both default.wd and tmp.wd should be the same after executing
those two lines. If you want to store both the old and new directories,
you should do it like this:
old.wd <- setwd(choose.dir())
new.wd <- getwd()
Duncan Murdoch
More information about the R-help
mailing list