提示'是'每次都得到.Filings

时间:2017-02-04 13:41:01

标签: r for-loop edgar

我将使用EDGAR软件包为R中的几家公司下载2005 10-K。我有一个迷你循环来测试哪个有效:

for (CIK in c(789019, 777676, 849399)){
  getFilings(2005,CIK,'10-K')
}

然而,每次运行时我都会得到是/否提示,我必须输入“是”':

Total number of filings to be downloaded=1. Do you want to download (yes/no)? yes
Total number of filings to be downloaded=1. Do you want to download (yes/no)? yes
Total number of filings to be downloaded=1. Do you want to download (yes/no)? yes

如何提示R回答“是”'每次跑步?谢谢

1 个答案:

答案 0 :(得分:3)

请记住在您的问题中包含一个可重现性最小的示例,包括library(...)和所有其他必要的命令:

library(edgar)
report <- getMasterIndex(2005)

我们可以通过做一些代码手术来绕过提示。在这里,我们检索getFilings的代码,并用一条消息替换要求提示的行。然后我们将新函数(my_getFilings)写入临时文件,并source该文件:

x <- capture.output(dput(edgar::getFilings))
x <- gsub("choice <- .*", "cat(paste(msg3, '\n')); choice <- 'yes'", x)
x <- gsub("^function", "my_getFilings <- function", x)
writeLines(x, con = tmp <- tempfile())
source(tmp)

一切都下载得很好:

for (CIK in c(789019, 777676, 849399)){
  my_getFilings(2005, CIK, '10-K')
}
list.files(file.path(getwd(), "Edgar filings"))
# [1] "777676_10-K_2005" "789019_10-K_2005" "849399_10-K_2005"
相关问题