R 可执行文件在写入一个 csv 后停止
我使用本教程制作了一个 Rexec 文件:http://www.r-datacollection.com/blog/Making-R-files-executable/
I made an Rexec file using this tutorial: http://www.r-datacollection.com/blog/Making-R-files-executable/
我使用了一个文件,当我打开 Rstudio 并运行它时,它会一直运行.但是,我制作的 Rexec 文件运行到第一个 csv,然后停止.有没有办法将 Rexec 文件保留为一个文件并让所有 csvs 运行,或者它必须成为多个文件?
I've made one using a files that runs all the way through when I open Rstudio and run it. But, the Rexec file I have made runs up to the first csv, and then stops. Is there a way to keep the Rexec file as one file and have all the csvs run, or must it become multiple files?
存在于一个文件中的有问题的代码是这样的:
The code in question, which exists in one file, is this:
#Measure the time taken
start.time <- Sys.time()
# Load functions in other R files
source("R/Functions.R")
source("R/Negatives Check.R")
source("R/Control Totals.R")
source("R/Validations.R")
# Load Packages
load_packages()
files = load_TZP()
files2 = load_TZP_stacked()
# Negatives Check---------------------------------------------------------------
write_csv(cbind(Name = names(files), create_output()),
paste0("Final CSV/Negatives Check ", gsub(":", ".", Sys.time()), ".csv"))
这是 .Rexec 文件停止的地方
# Control Totals Check----------------------------------------------------------
# Choose limit to account for rounding
total_limit = 10
write_csv(cbind(#Name = control_total_files,
#Check = control_total_checks,
create_output_totals()),
paste0("Final CSV/Control Totals ", gsub(":", ".", Sys.time()), ".csv"))
# Validations Check-------------------------------------------------------------
# Choose a limit for the difference, to account for rounding errors
limit = 0.1
write_csv(cbind(Name = valid_names,
Check = valid_checks,
create_output_geo()),
paste0("Final CSV/Validations ", gsub(":", ".", Sys.time()), ".csv"))
# Measure the time taken
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
你的工作目录(第一个是 RStudio,第二个是 Rexec)呢?他们是一样的吗?
What about your working directories (first for RStudio and second for Rexec)? Are they the same?
也许,您需要更改 Rexec 中的工作目录.
Maybe, you need to change the working directory in Rexec.
# Returns an absolute filepath of current working directory of the R process
getwd()
# setwd is used to set the working directory to dir
setwd("C:/Users/User/Documents") # for example