我正在R中的minimize()
包中运行QCA
函数。我必须多次调用该函数,并使用foreach
和doParallel
对其进行并行化。但是,由于我多次运行该函数,因此内存不足。因此,我正在寻找一种将结果从我的foreach循环写入文件的方法。我在想像JSON这样的东西可以很好地达到我的目的。以下是有关我要保存的内容的更多信息:
这些是我嵌套的foreach
循环:
x <-
foreach(c=causal_condition_group_C, .combine='cbind') %:%
foreach(b=causal_condition_group_B, .combine='cbind') %:%
foreach(a=causal_condition_group_A, .combine='cbind') %dopar% {
tryCatch({
minimize(temp, outcome = outcome, conditions = paste0(a,",",b,",",c, ", cause_D_1"), n.cut = 1, incl.cut = 0.400, include = "?", details = TRUE, use.letters = TRUE)
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
在foreach
循环完成对minimize()
函数的调用之后,我得到以下输出(有更多列)存储在x
中:
result.34 result.35 result.36 result.37 result.38
tt List,11 List,11 List,11 List,11 List,11
options List,10 List,10 List,10 List,10 List,10
negatives Numeric,2 Numeric,2 13 13 13
initials Character,7 Character,7 Character,9 Character,9 Character,9
PIchart Logical,21 Logical,21 Logical,36 Logical,36 Logical,36
primes Integer,12 Integer,12 Integer,12 Integer,12 Integer,12
solution List,1 List,1 List,1 List,1 List,1
essential Character,3 Character,3 Character,3 Character,3 Character,3
inputcases Character,7 Character,7 Character,9 Character,9 Character,9
pims List,3 List,3 List,3 List,3 List,3
IC List,4 List,4 List,4 List,4 List,4
numbers Numeric,4 Numeric,4 Numeric,4 Numeric,4 Numeric,4
SA List,1 List,1 List,1 List,1 List,1
call Expression Expression Expression Expression Expression
作为示例,以下是其中一个结果的tt
行的样子:
[[1]]
A: cause_A_1
B: cause_B_1
C: cause_C_2
D: cause_D_1
OUT: output value
n: number of cases in configuration
incl: sufficiency inclusion score
PRI: proportional reduction in inconsistency
A B C D OUT n incl PRI
1 0 0 0 0 1 1 0.469 0.381
4 0 0 1 1 1 2 0.423 0.325
5 0 1 0 0 1 8 0.421 0.328
6 0 1 0 1 1 1 0.478 0.365
8 0 1 1 1 1 1 0.434 0.344
9 1 0 0 0 1 2 0.409 0.284
13 1 1 0 0 0 4 0.332 0.223
14 1 1 0 1 1 2 0.407 0.285
15 1 1 1 0 1 1 0.443 0.295
16 1 1 1 1 1 20 0.436 0.378
我尝试编写整个列表列表,如下所示,该列表存储在变量x
中:
library(jsonlite)
toJSON(x, pretty = TRUE, auto_unbox = TRUE)
但是我得到以下错误代码:
Error: No method asJSON S3 class: QCA_tt
有人知道导致错误的确切原因以及如何解决该错误吗?谢谢!