是否可以停用RStudio控制台中的是/否提示?

时间:2019-09-05 07:34:26

标签: r console prompt

我正在使用R包中的一个功能,该功能称为RAC(用于水产养殖的R包)。在执行之前,它将在控制台窗口中生成一个Y / N提示。有没有办法停用提示或每次自动回答N?

函数Bass_pop_main将生成: Do you want to change the inputs? [y/n]

这是一个例子:

library(RAC)

setwd("../RAC_seabass") #working directory

userpath <- "../RAC_seabass" #userpath

Bass_pop_skeleton(userpath) #create input and output folders

forcings <- Bass_pop_dataloader(userpath) #load environmental variables

output <- Bass_pop_main("../RAC", forcings) #run growth model

1 个答案:

答案 0 :(得分:0)

不确定是否可以从外部提供任何设置,使您每次都能自动回答“否”。但是,我们可以根据需要更改Bass_pop_main的源代码并使用它。如果您在控制台中输入Bass_pop_main,则源代码可用。

library(RAC)

Bass_pop_main_revised <- function (userpath, forcings) {
   rm(list = ls())
   cat("Sea Bass population bioenergetic model\n")
   cat(" \n")
   currentpath = getwd()
   out_pre <- Bass_pop_pre(userpath, forcings)
   Param = out_pre[[1]]
   Tint = out_pre[[2]]
   Gint = out_pre[[3]]
   Food = out_pre[[4]]
   IC = out_pre[[5]]
   times = out_pre[[6]]
   Dates = out_pre[[7]]
   N = out_pre[[8]]
   CS = out_pre[[9]]
   out_RKsolver <- Bass_pop_loop(Param, Tint, Gint, Food, IC, times, N, userpath)
   out_post <- Bass_pop_post(userpath, out_RKsolver, times, Dates, N, CS)
   cat(" ")
   cat("End")
   return(out_post)
}

现在使用Bass_pop_main_revised函数代替Bass_pop_main,它将永远不会要求输入。

setwd("../RAC_seabass") 
userpath <- "../RAC_seabass" 
Bass_pop_skeleton(userpath) 
forcings <- Bass_pop_dataloader(userpath) 
output <- Bass_pop_main_revised("../RAC", forcings)