[R] doing 1000 permutations and doing test statistics distribution

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Wed Feb 5 17:11:56 CET 2020

On Wed, 5 Feb 2020 09:15:16 -0600
Ana Marija <sokovic.anamarija using gmail.com> wrote:

> I tried to solve the task via following code:

> all_results <- lapply(manyorders, function(ord) {

# ...

>  list(fit = fit, y1 = y1)
> })

> and I wrote all_results in a file
> write.table(all_results, file="all_res", sep = " ", row.names = FALSE,
> col.names = TRUE,quote=FALSE)

all_results is a list of lists of pairs of data.frames and MArrayLM
S3 objects, while write.table works best with data.frames (or things
that make sense when coerced to a data.frame). I am afraid that the
result of coercing a list of lists of lists into a data.frame may not
make sense.

What do you need the "all_res" file for? If you just want persistence
(save the data between runs of R programs, but not examine it
manually), consider using saveRDS/readRDS instead. If you need to
interoperate with non-R programs or want a text file for transparency
reasons, read on.

> when I tried to open the file:
> > a=read.table("all_res", header=T)  
> Error in read.table("all_res", header = T) :
>   more columns than column names

Do any of the strings stored in all_results contain spaces?
(y1[,'genelist'] might.) A combination of sep=" " and quote=FALSE could
make such data impossible to read back unambiguously. Does it help to
re-enable quote=TRUE or switch to a different sep (like "\t") that's
guaranteed to be absent from strings you are trying to save? Either
way, read.table() will not reconstruct the same all_results that was
fed to write.table() previously unless all_results is already a
data.frame (which it isn't).

Best regards,

More information about the R-help mailing list