在 CRAN 发布示例中处理下载的文件

问题描述 投票:0回答:1

我写了一个库,想发布到 CRAN。遵守所有要求给库添加了很多臃肿和烦人的额外内容,这些额外内容只存在于每个函数都有一个可运行的示例。由于这些函数依赖于彼此的输出,因此我必须包含大约 13 个额外的数据集,所有这些数据集都必须仔细记录。基本上我花了半年左右的时间来开发这些需求,并没有改进实际的功能。我现在在运行 devtools::check_win_devel() 时遇到以下问题:

在“oRaklE-Ex.R”中运行示例失败 错误最有可能发生在:

base::assign(".ptime", proc.time(), pos = "CheckExEnv")

名称:long_term_future

标题:未来几年的长期趋势预测

别名:long_term_future

** 示例

工作目录 <- getwd() setwd(tempdir()) example_longterm_future_predictions <- long_term_future(example_longterm_future_macro_data) Warning in readChar(con, 5L, useBytes = TRUE) : cannot open compressed file './FR/models/longterm/best_lm_model1.Rdata', probable reason 'No such file or directory' Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection Calls: long_term_future ->加载 -> readChar 执行停止

问题是我需要从先前的函数访问线性模型才能获得结果。我处理这个问题的方法如下:

  1. 我将当前工作目录路径保存到变量中

  2. 将 wd 切换为临时 wd

  3. 该函数检查当前 wd 是否包含“Temp”,如下所示:

    if (grepl("Temp", getwd())) {...}

  4. 如果是,则新建模型并保存

  5. 得到这样的模型:

    对于(1:3中的i){ model_path=paste0("./", unique(longterm_future_macro_data$country),"/models/longterm/best_lm_model",i,".Rdata") ...}

  6. 现在模型已加载,剩下的就可以了。

您将如何修复我遇到的错误?将模型保存在 inst/extdata/ 中并使用 system.file() 访问它不是一个选项,因为我有另一个需要加载 84 个模型的函数。

publish cran
1个回答
0
投票

所以答案是将检查临时文件夹的逻辑概括为:

if (grepl("Rtmp", getwd()))

而不是:

if (grepl("Temp", getwd())) 
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.