Prompt 'Yes' every time to getFilings

≯℡__Kan透↙ 提交于 2019-12-18 09:54:09

问题


I am going to download the 2005 10-Ks for several corporations in R using the EDGAR package. I have a mini loop to test which is working:

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

However each time this runs I get a yes/no prompt and I have to type '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
Total number of filings to be downloaded=1. Do you want to download (yes/no)? yes

How can I prompt R to answer 'yes' for each run? Thank you


回答1:


Please remember to include a minimal reproducible example in your question, including library(...) and all other necessary commands:

library(edgar)
report <- getMasterIndex(2005)

We can bypass the prompt by doing some code surgery. Here, we retrieve the code for getFilings, and replace the line that asks for the prompt with just a message. We then write the new function (my_getFilings) to a temporary file, and source that file:

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)

Everything downloads fine:

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"


来源:https://stackoverflow.com/questions/42041077/prompt-yes-every-time-to-getfilings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!