写一个csv

时间:2017-07-23 23:52:37

标签: r windows

我使用本教程创建了一个Rexec文件: http://www.r-datacollection.com/blog/Making-R-files-executable/

当我打开Rstudio并运行它时,我使用了一直运行的文件。但是,我制作的Rexec文件运行到第一个csv,然后停止。有没有办法将Rexec文件保存为一个文件并运行所有csv,或者它必须成为多个文件?

存在于一个文件中的相关代码是:

    #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

1 个答案:

答案 0 :(得分:0)

你的工作目录怎么样(第一个用于RStudio,第二个用于Rexec)?它们是一样的吗?

也许,您需要更改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