[R] setwd and list.files / linux

Marc Schwartz marc_schwartz at comcast.net
Fri Dec 5 16:02:03 CET 2008


Hi Lars,

I am having trouble replicating this problem, using the default
file/folder permissions on my Fedora 10 system.

When creating a new folder, I get:

mkdir Test

drwxrwxr-x  2 marcs marcs   4096 2008-12-05 08:17 Test


When creating a new file, I get:

touch Test.txt

-rw-rw-r-- 1 marcs marcs 0 2008-12-05 08:17 Test.txt


Even when modifying the file permissions to be similar to yours:

chmod 644 Test.txt

-rw-r--r-- 1 marcs marcs 0 2008-12-05 08:17 Test.txt


I can still read the file from a different folder.  It is likely that
your 'umask', which defines the default file/folder permissions on your
system is different than mine. For me, as a regular user, it is 002.
This value is usually defined in /etc/bashrc:

$ grep umask /etc/bashrc
	umask 002
	umask 022

The first value is for a regular user, the second for 'root'.

It is likely that your umask is 022 based upon the file permissions that
you list, as that would result in a default permission of 644. This
might mean that the default umask on RHEL is different than on Fedora,
or perhaps your default umask has been changed in ~/.bashrc.

I suspect that you might have a folder permission issue, rather than a
file permission issue and I think that would be consistent with the
behavior that you are observing.

I would check the permissions on each folder in the path that you are
trying to access to see if something is amiss there. Perhaps try using
setwd() on each folder in the datapath tree, starting at 'the top',
adding a new lower level folder each time, until it fails. That might
provide some guidance.

HTH,

Marc


on 12/05/2008 02:46 AM Lars Beckmann wrote:
> Hey Marc,
> 
> sorry I forgot to mention it. I am the owner of the path, which is in my home directory. I can change the read/write/execute privileges.  All users have - at least - read privileges for all files and the directory:
> 
> hpc36 40: ls -la *.tped
> -rw-r--r--  1 cremer C020 205487231 Dec  3 17:35 chr10.tped
> -rw-r--r--  1 cremer C020 192067641 Dec  3 17:37 chr11.tped
> -rw-r--r--  1 cremer C020 192243483 Dec  3 17:38 chr12.tped
> 
> etc
>  
> A workaround I found now is to start R in the respective directory from the command line, which will set working directory to current directory. list.files will work then too:
> 
> list.file(".",pattern="\\.tped")
> 
> The problem now is to start a script via R CMD BATCH from a different directory, because setwd() will not work:
> 
>> datapath<-'/nfs/home/m/cremer/gaw/data/traws_chrs/'
>>
>> getwd()
> [1] "/nfs/home/m/cremer/gaw/code/plink"
>> setwd(datapath)
> Error in setwd(datapath) : cannot change working directory
> Execution halted
>    
> Lars
> 
> -------- Original-Nachricht --------
>> Datum: Thu, 04 Dec 2008 10:58:16 -0600
>> Von: Marc Schwartz <marc_schwartz at comcast.net>
>> An: Lars Beckmann <Lars.Beckmann at gmx.net>
>> CC: r-help at r-project.org
>> Betreff: Re: [R] setwd and list.files / linux
> 
>> on 12/04/2008 10:38 AM Lars Beckmann wrote:
>>> Hey,
>>>
>>> two questions regarding setwd and list.files:
>>>
>>> I try to use the function list.files:
>>>
>>>> datapath<-'/nfs/home/m/cremer/gaw/data/traws_chrs'
>>>> fl<-list.files(datapath, pattern="\\.tped")
>>> but I get the following error message:
>>>
>>> Warning message:
>>> In list.files(datapath, pattern = "\\.tped") :
>>>   list.files: '/nfs/home/m/cremer/gaw/data/traws_chrs/' is not a
>> readable directory
>>>> fl
>>> character(0)
>>>
>>> The use of setwd also does not work:
>>>
>>>> setwd(datapath)
>>> Error in setwd(datapath) : cannot change working directory
>>>
>>>
>>> datapath exists and it doesn't matter whether I use single quotes ' or
>> double quotes "
>>> Any help?
>>>
>>> Lars
>> You do not have read privileges to the path in question. Either you or
>> your SysAdmin will have to grant the appropriate privileges so that you
>> can read the files in the path.
>>
>> HTH,
>>
>> Marc Schwartz
>>



More information about the R-help mailing list