我在R中使用furrr运行并行计算,计算需要访问web,并且需要进行身份验证。如果我运行一个并行进程,每个进程都需要进行身份验证。在下面,我有6个过程。因此,我需要先对这六个进程进行身份验证,然后运行计算。我不知道如何使用furrr来做到这一点。因此,我在每次运行时都要进行身份验证,这是非常低效率的。
下面是一个简单的例子,用于说明。它不能工作,因为我不能共享api.configure函数,但希望您能理解这个想法。
谢谢
library(tidyverse)
library(furrr)
plan(multiprocess, workers = 6)
testdf = starwars %>%
select(-films, -vehicles, -starships) %>%
future_pmap_dfr(.f = function(...){
api.configure(username = "username", password = "password")
currentrow = tibble(...)
l = tibble(name = currentrow$name, height = currentrow$height)
return(l)
})发布于 2021-02-04 11:47:41
解决这一问题的方法是要求API的开发人员在API包中添加变量,以测试连接是否打开。这样,如果连接未打开,则在每个future进程上进行一次身份验证,一旦完成,对该进程的所有后续API身份验证调用都将由if子句停止。
发布于 2020-09-29 09:39:11
试着在地图之前打开连接:
library(tidyverse)
library(furrr)
plan(multiprocess, workers = 6)
future_options(globals = T) # this should be the default
api.configure(username = "username", password = "password")
ls(all=TRUE) #Check if new environment variables are available to save connexion
testdf = starwars %>%
select(-films, -vehicles, -starships) %>%
future_pmap_dfr(.f = function(...){
currentrow = tibble(...)
l = tibble(name = currentrow$name, height = currentrow$height)
return(l)
})https://stackoverflow.com/questions/64116267
复制相似问题