Menu
  • HOME
  • TAGS

Application of mclapply() to a function writing to a global variable

r,parallel-processing,lapply,mclapply

The problem is the <<- which is bad practice in general as far as I can gather. The function can be rearranged thusly: readNhist <- function(n,mconst) { l <- raster(filename, varname=var, band=n, na.rm=T) gain(l) <- mconst hist <- hist(l, plot=F, breaks=histbreaks,right=FALSE) return(hist) } And called like this: hists <- mclapply(...

R, the environment of mclapply and removing variables

r,memory,parallel-processing,mclapply

You should call the gc function after removing the variable so that the memory associated with the object is freed by the garbage collector sooner rather than later. The rm function only removes the reference to the data, while the actual object may continue to exist until the garbage collector...

Parallelization: package “parallel” instead of “mclapply”

r,parallel-processing,mclapply

Your first code calls a function function(file, fID) Your second code, by contrast, uses function(dirPath,fID) That’s the error....

how to track progress in mclapply in R in parallel package

r,parallel-processing,lapply,mclapply

This is an update of my related answer. library(parallel) finalResult <- local({ f <- fifo(tempfile(), open="w+b", blocking=T) if (inherits(parallel:::mcfork(), "masterProcess")) { # Child progress <- 0.0 while (progress < 1 && !isIncomplete(f)) { msg <- readBin(f, "double") progress <- progress + as.numeric(msg) cat(sprintf("Progress: %.2f%%\n", progress * 100)) } parallel:::mcexit() }...

function tm::tm_map encounter an error

r,tm,mclapply

First, make sure the text is encoded in UTF-8 (if you can open the file in a text editor then you should be able to modify the encoding when you save it). If that doesn't fix the problem, then try adding the argument "mc.cores = 1" to the tm_map function.