cannot open the connection error with parLapply

后端 未结 2 1263
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 13:46

I successfully processed some data on a 4 core computer using parLapply, using a code like below:

require(\"parallel\")
setwd(\"C:/...\")

file_summary<-read.         


        
相关标签:
2条回答
  • 2021-01-26 14:18

    The only operation that I see in "myfunction" that can generate a "cannot open the connection" error is "read.table". You might want to add the following right before calling read.table:

    if (! file.exists(new_file))
      stop(paste(new_file, "does not exist"))
    

    It might also be useful to check that the worker has permission to read the file:

    if (file.access(new_file, mode=4) == -1)
      stop(paste("no read permission on", new_file))
    

    It seems worthwhile to rule out these problems.

    0 讨论(0)
  • 2021-01-26 14:19

    You need to pass the current directory as an argument in parLapply() to your function. Inside your function myfunction you need to reset the working directory by setwd():

    myfunction = function(k, wd_)
    {
          setwd(wd_)
            ...
    }
    ...
    wd_ = getwd()
    Results <- parLapply(Cl, c(1:n_tasks), myfunction, wd_)
    

    N.B. make sure R/R Studio/R Script all are not blocked by the firewall.

    0 讨论(0)
提交回复
热议问题