R 可执行文件在写入一个 csv 后停止 [英] R executable file stops after writing one csv

查看:34
本文介绍了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

这篇关于R 可执行文件在写入一个 csv 后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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