Re: [R] importing a list

From: <grazia_at_stat.columbia.edu>
Date: Thu 11 May 2006 - 03:05:00 EST

Robert,
thanks first of all.
Actually, the txt file I want to read as a list is like that:

$y
$y$mod.1
[1] "impute.1.y=glm(I(y>0)~x+ z+ w,family=binomial(link =logit),data= data)"

$y$mod.2
[1] "impute.2.y=lm(I(log (y))~x+ z+ w,subset=y>0)"

$x
[1] "impute.x=lm(x~y+ z+ w, data= data)"

$z
[1] "impute.z=lm(z~y+ x+ w,data= data)"

that is a list of 4 elements with the first element a list as well.

To save the file I'm using this function:

list2ascii <- function(x,
file=paste(deparse(substitute(x)),".txt",sep="")) {

    tmp.wid = getOption("width")
    options(width=10000)
    sink(file)
    print(x)
    sink()
    options(width=tmp.wid)
    return(invisible(NULL))
    }

So, I should read it using
read.fwf("models.txt", width=getOption("width"))

The problem is that I'm not getting back a list! Probably I have to play with write.table?!! thanks,
grazia

On Wed, 10 May 2006, Robert Citek wrote:

> Hello Grazia,
>
> On May 10, 2006, at 10:23 AM, grazia@stat.columbia.edu wrote:
>> I'm trying to automate some regression operations in R leaving the
>> possibility to modify the predictors in the regression.
>>
>> For example, I have saved in a list the results and then exported as a txt
>> file, in which we can modify the predictors, putting for example
>> lm(y~x^2) instead of having lm(y~x) as in the original model.
>>
>> Now, I need to import in R the txt file as a list to evaluate the model.
>> Is that possible?
>>
>> I played around with source() and file() but can't figure it out.
>
> What OS are you using? When you say the list is in a text file, how is the
> text file structured, e.g. CSV, TSV, fixed-width, other?
>
> Here's an example of creating, writing, and reading a data.frame:
>
> d <- data.frame(cbind(x=1, y=1:10))
> write.table(d, file="r-data.txt", sep="\t", na="", quote=FALSE, row.names =
> FALSE)
> d.new <- read.delim("r-data.txt")
>
> HTH.
>
> Regards,
> - Robert
> http://www.cwelug.org/downloads
> Help others get OpenSource software. Distribute FLOSS
> for Windows, Linux, *BSD, and MacOS X with BitTorrent
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu May 11 03:58:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 11 May 2006 - 06:10:04 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.