我希望能够使用purrr::walk函数并保存相关结果。在这个问题中,我有四个数据框需要分别写入四个文件中。以下是我的代码以及出现的错误。请注意,.x和...都是相同长度的列表。我相信我犯了一些简单的错误,但不确定是什么。谢谢帮忙。
# load libs
library(purrr)
# create dfs to loop over
df <- data.frame(
a = rnorm(10),
b = rnorm(10),
c = rnorm(10),
d = rnorm(10)
)
obj <- list(df1 = df, df2 = df, df3 = df, df4 = df )
# create file names to loop over
path <- "/user/home/"
folder <- "RDa/"
names <- c("df1", "df2", "df3", "df4")
fnames <- lapply(names, function(x) paste0(path, folder, x, ".RDa"))
# iterate
walk(obj, save, fnames)
Error in .f(.x[[i]], ...) : object ‘.x[[i]]’ not found
会话信息
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
Running under: OS X 10.7.5 (Lion)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] purrr_0.2.2
loaded via a namespace (and not attached):
[1] magrittr_1.5 tools_3.2.1 Rcpp_0.12.3 knitr_1.12.3