cmu-delphi / cmu-delphi/DelphiRF
If `model_save_dir` does not exist, an error is thrown with a suboptimal message
- Dominant language
- R
- Stars
- 1
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Following the README example:
``` r
library(DelphiRF)
library(ggplot2)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
data(ma_dph)
value_col <- "confirmed_case_7d_avg"
refd_col <- "test_date"
lag_col <- "lag"
ref_lag <- 14
smoothed <- TRUE
# Preprocess the data for a specific location
df <- data_preprocessing(
ma_dph,
value_col = "confirmed_case_7d_avg",
refd_col = "test_date",
lag_col = "lag",
ref_lag = 14,
smoothed = TRUE
)
# Define the test date range
test_dates <- seq(from = as.Date("2022-06-15"),
to = as.Date("2022-06-30"),
by = "day")
# Filter training data
train_data <- df %>%
filter(report_date < min(test_dates))
# Add weighting-related features to training data
# This should be done after the train_data is filtered with test_date
train_data <- add_weights_related(train_data)
# Filter test data
test_data <- df %>%
filter(report_date %in% test_dates)
# Run DelphiRF for forecasting
results <- DelphiRF(df, as.Date("2022-06-01"))
#> Warning in dir.create(path): cannot create dir
#> './receiving/testdata_count_state', reason 'No such file or directory'
#> Warning in quantile_genlasso_lp(x = x, y = y, d = d, tau = tau, lambda =
#> lambda, : gurobi R package not installed, using Rglpk instead.
#> Warning in dir.create(path): cannot create dir
#> './receiving/testdata_count_state', reason 'No such file or directory'
#> Warning in gzfile(file, mode): cannot open compressed file
#> './receiving/testdata_count_state/20220601_ma_lag0_tau_all_tw365_lambda0.1_gamma0.1.rds',
#> probable reason 'No such file or directory'
#> Error in `gzfile()`:
#> ! cannot open the connection
```
Created on 2026-06-01 with [reprex v2.1.1](https://reprex.tidyverse.org)
For anyone who hasn't seen this pattern, with `dir.create` confusingly warning "No such file or directory" ("yeah, of course it doesn't exist; that's why I said to create it"), followed by something supposedly about `gzfile`, it may not be obvious what is going on.
Two possible approaches:
- Have `DelphiRF()` check for `model_save_dir`'s existence and issue an error with a better message.
- Create `model_save_dir` if it doesn't exist. This may cause issues with [CRAN policies](https://cran.r-project.org/web/packages/policies.html), particularly with the current default `model_save_dir`:
> Packages should not write in the user’s home filespace (including clipboards), nor anywhere else on the file system apart from the R session’s temporary directory (or during installation in the location pointed to by TMPDIR: and such usage should be cleaned up). Installing into the system’s R installation (e.g., scripts to its bin directory) is not allowed.
> Limited exceptions may be allowed in interactive sessions if the package obtains confirmation from the user.
> For R version 4.0 or later (hence a version dependency is required or only conditional use is possible), packages may store user-specific data, configuration and cache files in their respective user directories obtained from tools::R_user_dir(), provided that by default sizes are kept as small as possible and the contents are actively managed (including removing outdated material).
It would probably be easiest to just default to a temp directory, to avoid having to manage clean-up of files in a the `R_user_dir()` approach.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.