每次提示“是"以获取文件 [英] Prompt 'Yes' every time to getFilings

查看:107
本文介绍了每次提示“是"以获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用EDGAR软件包为R中的多家公司下载2005 10-K.我有一个迷你循环来测试它是否正常工作:

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

我如何提示R每次运行都回答是"?谢谢

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

推荐答案

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

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

library(edgar)
report <- getMasterIndex(2005)

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

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)

一切下载正常:

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"

这篇关于每次提示“是"以获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆