提示“是”每次都会在R中得到结果 [英] Prompt 'Yes' every time to getFilings in R

查看:222
本文介绍了提示“是”每次都会在R中得到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

pre code c(ck(789019,777676,843993)){
getFilings(2005,CIK,'10 -K')
}

然而每次运行,我得到一个是/否提示,我必须输入'是':

 要归档的总数下载= 1。你想下载(是/否)?是
要下载的申请总数= 1。你想下载(是/否)?是
要下载的申请总数= 1。你想下载(是/否)?是

如何提示R为每次运行回答是?谢谢

解决方案

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

  library(edgar)
report< - getMasterIndex(2005)

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

  x < -  capture.output(dput(edgar :: getFilings))
x< - gsub(choice< - 。 *,cat(paste(msg3,'\\\
')); 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_2005789019_10-K_2005849399_10-K_2005


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

解决方案

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"

这篇关于提示“是”每次都会在R中得到结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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