【问题标题】:R executable file stops after writing one csvR 可执行文件在写入一个 csv 后停止
【发布时间】:2017-07-23 23:52:37
【问题描述】:

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

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

有问题的代码存在于一个文件中,是这样的:

    #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

【问题讨论】:

    标签: r windows


    【解决方案1】:

    你的工作目录(第一个是 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
    

    【讨论】:

    • 谢谢,Arkadiy,这解决了这个问题。原始文件位于 R 项目中,该项目具有灵活的工作目录,具体取决于您放置它的位置。我为您的评论投了票,但由于我没有声誉,因此未显示。
    • 你可以接受我的回答。 stackoverflow.com/help/someone-answers
    猜你喜欢
    • 2020-12-09
    • 2017-01-07
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多