[R] setwd() command on windows vs. linux/unix

William Dunlap wdunlap at tibco.com
Mon Jul 27 22:29:56 CEST 2015


You can get a more informative error message from system("bash -c 'cd
yourDirectory'"), although it will not take R to that directory if there
are no problems.  E.g.,  I did in a shell
  % mkdir -p dir/subdir
  % chmod -x dir
to make an untraversable directory 'dir' and a subdirectory of it.  Then in
R I get:
  > setwd("dir/subdir")
  Error in setwd("dir/subdir") : cannot change working directory
  > system("bash -c 'cd dir/subdir'")
  bash: line 0: cd: dir/subdir: Permission denied
And for a nonexistent directory I get:
  > setwd("no/such/directory")
  Error in setwd("no/such/directory") : cannot change working directory
  > system("bash -c 'cd no/such/directory'")
  bash: line 0: cd: no/such/directory: No such file or directory

(It would be nice if the name of the offending directory and a reason were
given in setwd's error message, but that would require someone to write the
code.)



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Jul 27, 2015 at 12:38 PM, Chris <chris.barker at barkerstats.com>
wrote:

>
> I have a script that runs correctly (no errors) on Windows, the first
> command is a "setwd(.....windows directory)"I installed the script on a
> Linux machine and changed the windows directory reference to the correct
> directory on the linux machine.when I ran the script I got a message that
> "cannot change working directory". I confirmed I have read and write access
> to the directory.I mainly run R on windows infrequently use linux/unix and
> would appreciate suggestions.thanks in advance Chris Barker, Ph.D.
> Adjunct Associate Professor of Biostatistics - UIC-SPH
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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]]



More information about the R-help mailing list