[R] read.table : how to condition on error while opening file?

2009-02-19 Thread Stephane Bourgeois
Hi,

 

I'm using read.table in a loop, to read in multiple files. The problem
is that when a file is missing there is an error message and the loop is
broken; what I'd like to do is to test for the error and simply do
next instead of breaking the loop. Anybody knows how to do that?

 

Example: 

 

filelist - c(file1.txt, file2.txt, file3.txt)

 

for (i in 1:3) {

  if (read.table(filelist[i]) == ERROR LOADING FILE) {
# this is where I do not know how to write the condition

print(paste(error opening file , filelist[i], sep=))

next

  } else {

tmp - read.table(filelist[i])

  }

}

 

 

Cheers,

 

Stephane




-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 

 Limited, a charity registered in England with number 1021457 and a 
 compa
ny registered in England with number 2742969, whose registered 
 office is 2
15 Euston Road, London, NW1 2BE. 



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Font size in plots (I do NOT understand par help)

2008-08-06 Thread Stephane Bourgeois
Hi,

 

I do not get how par works, help please.

 

Let's say I have a simple plot: plot(1:10)

 

I want to change the font size for the x axis... how do I do that?

 

Thank you,

 

Stephane




-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 

 Limited, a charity registered in England with number 1021457 and a 
 compa
ny registered in England with number 2742969, whose registered 
 office is 2
15 Euston Road, London, NW1 2BE. 



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] attributing values to dataframe positions following eval

2008-07-08 Thread Stephane Bourgeois
Hi everybody,

 

I've been looking around, but can't seem to find the answer.

 

I get a list of names (which vary, so I never know them in advance), and
transform them into variables, each of which is a dataframe, using
assign:

 

polyList - c(rs123, rs124, rs555, rs000)

numPoly - length(polyList)

 

for (k in 1:numPoly) {

  assign(polyList[k], data.frame(matrix(NA, ncol=3, nrow=3)))

}

 

polyList - lapply(polyList, as.name)

 

I can see the resulting dataframe associated to rs123 (for example)
using:

 

 eval(polyList[[1]])

  X1 X2 X3

1 NA NA NA

2 NA NA NA

3 NA NA NA

 

And see the value in row 1, column 1 with:

 

 eval(polyList[[1]])[1,1]

[1] NA

 

Now, I want to change the values in the dataframe... that's what I can't
manage to do:

 

 eval(polyList[[1]])[1,1] - 5

Error in eval(polyList[[1]])[1, 1] - 5 : 

  could not find function eval-

 

Anybody has an idea on how to do that?

 

Thank you,

 

Stephane

 

PS:  yes, I'm aware that using arrays and dataframes instead of going
through the creation of variables may be more practical, but the context
is much more complex than the presented example (and in that specific
case, having these variables is a requirement)

 




-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 

 Limited, a charity registered in England with number 1021457 and a 
 compa
ny registered in England with number 2742969, whose registered 
 office is 2
15 Euston Road, London, NW1 2BE. 



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] How to get an argument dynamically from a list?

2008-06-29 Thread Stephane Bourgeois
Hi,

I'd like to get an argument (I think it's the right term) dynamically from a 
list, but cannot manage to do it.

Here is the code I use:

#output given by database

BOB - c('A/A', 'C/C', '15/27')
MARY - c('A/A', NA, '13/12')
JOHN - c('A/A', 'C/A', '154/35')
CLIFF - c('A/C', 'C/C', '15/12')
PAM - c('A/C', 'C/A', '13/12')
sampleList - c(BOB, MARY, JOHN, CLIFF, PAM)
polyList - c(rs123, rs124, rs555)

#make dataframe with data

data.raw - data.frame(t(do.call(data.frame, lapply(sampleList, get
names(data.raw) - polyList
row.names(data.raw) - sampleList

I want to get, for example, data.raw$rs124 using polyList.

I tried

 get(paste(data.raw$, polyList[2], sep=))
Error in get(paste(data.raw$, polyList[2], sep = )) : 
  variable data.raw$rs124 was not found
  
but it's obviously not the right way, data.raw$rs124 not being a variable per 
se.

Any idea about how I could do that?

Thanks,

Stephane
__
R-help@r-project.org 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.


[R] creating a dataframe using a list of the variable names

2008-06-28 Thread Stephane Bourgeois
Hello,

I'm fairly new to R, and despite spending quite some time exploring, testing, 
and looking for answers, I still have a couple of questions remaining...

The first one is about creating a dataframe using a list of the variable names .

I get this output file from a database:

BOB - c('A/A', 'C/C', '15/27')
MARY - c('A/A', NA, '13/12')
JOHN - c('A/A', 'C/A', '154/35')
CLIFF - c('A/C', 'C/C', '15/12')
PAM - c('A/C', 'C/A', '13/12')

sampleList - c(BOB, MARY, JOHN, CLIFF, PAM)
polyList - c(rs123, rs124, rs555)

to create a dataframe with the data I use:

data.raw - data.frame(BOB, MARY, JOHN, CLIFF, PAM, row.names=polyList)

which works fine, but when there are several hundreds samples... well, you 
guess my problem.

I'd like to create the dataframe using the list of the variables, contained in 
sampleList - i.e. something like data.frame(function(sampleList), 
row.names=polyList)

Is that possible, and if yes, how?

Thanks in advance,

Stephane
__
R-help@r-project.org 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.