Re: [R] making code (loop) more efficient

2020-12-16 Thread Ana Marija
Indeed it was the issue with data.table. I converted it to data.frame and it worked like a charm. Thank you so much for your insight! This is the code that worked: library(parallel) library(data.table) library(doSNOW) n <- parallel::detectCores() cl <- parallel::makeCluster(n, type = "SOCK")

Re: [R] making code (loop) more efficient

2020-12-16 Thread Ana Marija
HI Jim, this is what I as running: library(parallel) library(data.table) library(foreach) library(doSNOW) n <- parallel::detectCores() cl <- parallel::makeCluster(n, type = "SOCK") doSNOW::registerDoSNOW(cl) files <- list.files("/WEIGHTS1/Retina", pattern=".RDat", ignore.case=T) lst_out <-

Re: [R] making code (loop) more efficient

2020-12-15 Thread Jim Lemon
Hi Ana, Back on the job. I'm not sure how this will work in your setup, but here is a try: a<-read.table(text="top1 blup lasso enet rs4980905:184404:C:A 0.07692622 -1.881795e-04 00 rs7978751:187541:G:C 0.62411425 9.934994e-04 00 rs2368831:188285:C:T 0.69529158 1.211028e-03

Re: [R] making code (loop) more efficient

2020-12-15 Thread Ana Marija
Hi Jim, as always you're completely right, this is what is happening: > head(a) top1 blup lasso enet rs4980905:184404:C:A 0.07692622 -1.881795e-04 00 rs7978751:187541:G:C 0.62411425 9.934994e-04 00 rs2368831:188285:C:T 0.69529158

Re: [R] making code (loop) more efficient

2020-12-15 Thread Jim Lemon
Hi Ana, I would look at "data" in your second example and see if it contains a column named "blup" or just the values that were extracted from a$blup. Also, I assume that weight=blup looks for an object named "blup", which may not be there. Jim On Wed, Dec 16, 2020 at 1:20 PM Ana Marija wrote:

Re: [R] making code (loop) more efficient

2020-12-15 Thread Ana Marija
Hi Jim, Maybe my post is confusing. so "dd" came from my slow code and I don't use it again in parallelized code. So for example for one of my files: if i="retina.ENSG0120647.wgt.RDat" > a <- get(load(i)) > head(a) top1 blup lasso enet

Re: [R] making code (loop) more efficient

2020-12-15 Thread Jim Lemon
Hi Ana, My guess is that in your second code fragment you are assigning the rownames of "a" and the _values_ contained in a$blup to the data.table "data". As I don't have much experience with data tables I may be wrong, but I suspect that the column name "blup" may not be visible or even present

[R] making code (loop) more efficient

2020-12-15 Thread Ana Marija
Hello, I made a terribly inefficient code which runs forever but it does run. library(dplyr) library(splitstackshape) datalist = list() files <- list.files("/WEIGHTS1/Retina", pattern=".RDat", ignore.case=T) for(i in files) { a<-get(load(i)) names <- rownames(a) data <-