Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if cache folder not previously created #85

Closed
Robinlovelace opened this issue Sep 7, 2024 · 1 comment · Fixed by #86
Closed

Error if cache folder not previously created #85

Robinlovelace opened this issue Sep 7, 2024 · 1 comment · Fixed by #86
Assignees

Comments

@Robinlovelace
Copy link
Collaborator

I hit the following error message, seems to be due to the 'cache folder' is not being present first time spod_get() runs:

od_data <- spod_get(type = "od", dates = "2023-01-02")
#> Error: [ENOENT] Failed to search directory '...data/metadata_cache': no such file or directory

After running the following it works:

dir.create("data/metadata_cache")
remotes::install_github("ropenspain/spanishoddata")
#> Using GitHub PAT from the git credential store.
#> Skipping install of 'spanishoddata' from a github remote, the SHA1 (972ffa35) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(spanishoddata)
dir <- "C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data"
dir.exists(dir)
#> [1] TRUE
Sys.setenv(SPANISH_OD_DATA_DIR = dir)
od_data <- spod_get(type = "od", dates = "2023-01-02")
#> Error: [ENOENT] Failed to search directory 'C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/metadata_cache': no such file or directory
list.files(dir, recursive = TRUE)
#> [1] "data_links_v2_2024-09-05.xml"                                                                                            
#> [2] "data_links_v2_2024-09-06.xml"                                                                                            
#> [3] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2023/month=1/day=2/Viajes_distritos.csv.gz"
#> [4] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2024/month=1/day=1/Viajes_distritos.csv.gz"
#> [5] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2024/month=1/day=2/Viajes_distritos.csv.gz"
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.utf8
#>  ctype    English_United Kingdom.utf8
#>  tz       Europe/London
#>  date     2024-09-07
#>  pandoc   3.2.1 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version date (UTC) lib source
#>  cachem          1.1.0   2024-05-16 [1] CRAN (R 4.4.1)
#>  cli             3.6.3   2024-06-21 [1] CRAN (R 4.4.1)
#>  curl            5.2.2   2024-08-26 [1] CRAN (R 4.4.1)
#>  devtools        2.4.5   2022-10-11 [1] CRAN (R 4.4.1)
#>  digest          0.6.36  2024-06-23 [1] CRAN (R 4.4.1)
#>  ellipsis        0.3.2   2021-04-29 [1] CRAN (R 4.4.1)
#>  evaluate        0.24.0  2024-06-10 [1] CRAN (R 4.4.1)
#>  fansi           1.0.6   2023-12-08 [1] CRAN (R 4.4.1)
#>  fastmap         1.2.0   2024-05-15 [1] CRAN (R 4.4.1)
#>  fs              1.6.4   2024-04-25 [1] CRAN (R 4.4.1)
#>  generics        0.1.3   2022-07-05 [1] CRAN (R 4.4.1)
#>  glue            1.7.0   2024-01-09 [1] CRAN (R 4.4.1)
#>  htmltools       0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)
#>  htmlwidgets     1.6.4   2023-12-06 [1] CRAN (R 4.4.1)
#>  httpuv          1.6.15  2024-03-26 [1] CRAN (R 4.4.1)
#>  knitr           1.48    2024-07-07 [1] CRAN (R 4.4.1)
#>  later           1.3.2   2023-12-06 [1] CRAN (R 4.4.1)
#>  lifecycle       1.0.4   2023-11-07 [1] CRAN (R 4.4.1)
#>  lubridate       1.9.3   2023-09-27 [1] CRAN (R 4.4.1)
#>  magrittr        2.0.3   2022-03-30 [1] CRAN (R 4.4.1)
#>  memoise         2.0.1   2021-11-26 [1] CRAN (R 4.4.1)
#>  mime            0.12    2021-09-28 [1] CRAN (R 4.4.0)
#>  miniUI          0.1.1.1 2018-05-18 [1] CRAN (R 4.4.1)
#>  pillar          1.9.0   2023-03-22 [1] CRAN (R 4.4.1)
#>  pkgbuild        1.4.4   2024-03-17 [1] CRAN (R 4.4.1)
#>  pkgconfig       2.0.3   2019-09-22 [1] CRAN (R 4.4.1)
#>  pkgload         1.4.0   2024-06-28 [1] CRAN (R 4.4.1)
#>  profvis         0.3.8   2023-05-02 [1] CRAN (R 4.4.1)
#>  promises        1.3.0   2024-04-05 [1] CRAN (R 4.4.1)
#>  purrr           1.0.2   2023-08-10 [1] CRAN (R 4.4.1)
#>  R.cache         0.16.0  2022-07-21 [1] CRAN (R 4.4.1)
#>  R.methodsS3     1.8.2   2022-06-13 [1] CRAN (R 4.4.0)
#>  R.oo            1.26.0  2024-01-24 [1] CRAN (R 4.4.0)
#>  R.utils         2.12.3  2023-11-18 [1] CRAN (R 4.4.1)
#>  R6              2.5.1   2021-08-19 [1] CRAN (R 4.4.1)
#>  Rcpp            1.0.13  2024-07-17 [1] CRAN (R 4.4.1)
#>  remotes         2.5.0   2024-03-17 [1] CRAN (R 4.4.1)
#>  reprex          2.1.0   2024-01-11 [1] CRAN (R 4.4.1)
#>  rlang           1.1.4   2024-06-04 [1] CRAN (R 4.4.1)
#>  rmarkdown       2.28    2024-08-17 [1] CRAN (R 4.4.1)
#>  sessioninfo     1.2.2   2021-12-06 [1] CRAN (R 4.4.1)
#>  shiny           1.8.1.1 2024-04-02 [1] CRAN (R 4.4.1)
#>  spanishoddata * 0.0.1   2024-09-07 [1] Github (ropenspain/spanishoddata@972ffa3)
#>  stringi         1.8.4   2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr         1.5.1   2023-11-14 [1] CRAN (R 4.4.1)
#>  styler          1.10.3  2024-04-07 [1] CRAN (R 4.4.1)
#>  tibble          3.2.1   2023-03-20 [1] CRAN (R 4.4.1)
#>  timechange      0.3.0   2024-01-18 [1] CRAN (R 4.4.1)
#>  urlchecker      1.0.1   2021-11-30 [1] CRAN (R 4.4.1)
#>  usethis         2.2.3   2024-02-19 [1] CRAN (R 4.4.1)
#>  utf8            1.2.4   2023-10-22 [1] CRAN (R 4.4.1)
#>  vctrs           0.6.5   2023-12-01 [1] CRAN (R 4.4.1)
#>  withr           3.0.1   2024-07-31 [1] CRAN (R 4.4.1)
#>  xfun            0.45    2024-06-16 [1] CRAN (R 4.4.1)
#>  xtable          1.8-4   2019-04-21 [1] CRAN (R 4.4.1)
#>  yaml            2.3.8   2023-12-11 [1] CRAN (R 4.4.0)
#> 
#>  [1] C:/Users/georl_admin/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2024-09-07 with reprex v2.1.0

And after creating the directory:

remotes::install_github("ropenspain/spanishoddata")
#> Using GitHub PAT from the git credential store.
#> Skipping install of 'spanishoddata' from a github remote, the SHA1 (972ffa35) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(spanishoddata)
dir <- "C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data"
dir.exists(dir)
#> [1] TRUE
dir.create(file.path(dir, "metadata_cache"), recursive = TRUE)
#> Warning in dir.create(file.path(dir, "metadata_cache"), recursive = TRUE):
#> 'C:\Users\georl_admin\github\robinlovelace\spanishoddata_paper\data\metadata_cache'
#> already exists
Sys.setenv(SPANISH_OD_DATA_DIR = dir)
od_data <- spod_get(type = "od", dates = "2023-01-02")
#> Saving the file to: C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/metadata_cache/data_links_v2_2024-09-07.xml
#> Data version detected from dates: 2
#> Using existing data links xml: C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/metadata_cache/data_links_v2_2024-09-07.xml
#> Using existing data links xml: C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/metadata_cache/data_links_v2_2024-09-07.xml
#> Deleting source `C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/clean_data/v2/zones/distritos_mitma.gpkg' failed
#> Writing layer `distritos_mitma' to data source 
#>   `C:/Users/georl_admin/github/robinlovelace/spanishoddata_paper/data/clean_data/v2/zones/distritos_mitma.gpkg' using driver `GPKG'
#> Writing 3909 features with 3 fields and geometry type Unknown (any).
list.files(dir, recursive = TRUE)
#>  [1] "clean_data/v2/zones/distritos_mitma.gpkg"                                                                                
#>  [2] "data_links_v2_2024-09-05.xml"                                                                                            
#>  [3] "data_links_v2_2024-09-06.xml"                                                                                            
#>  [4] "metadata_cache/data_links_v2_2024-09-07.xml"                                                                             
#>  [5] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2023/month=1/day=2/Viajes_distritos.csv.gz"
#>  [6] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2024/month=1/day=1/Viajes_distritos.csv.gz"
#>  [7] "raw_data_cache/v2/estudios_basicos/por-distritos/viajes/ficheros-diarios/year=2024/month=1/day=2/Viajes_distritos.csv.gz"
#>  [8] "raw_data_cache/v2/zonificacion/poblacion.csv"                                                                            
#>  [9] "raw_data_cache/v2/zonificacion/relacion_ine_zonificacionMitma.csv"                                                       
#> [10] "raw_data_cache/v2/zonificacion/zonificacion_distritos/nombres_distritos.csv"                                             
#> [11] "raw_data_cache/v2/zonificacion/zonificacion_distritos/poblacion_distritos.csv"                                           
#> [12] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.cpg"                                        
#> [13] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.dbf"                                        
#> [14] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.prj"                                        
#> [15] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.qmd"                                        
#> [16] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.qpj"                                        
#> [17] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.shp"                                        
#> [18] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos.shx"                                        
#> [19] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.cpg"                             
#> [20] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.dbf"                             
#> [21] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.prj"                             
#> [22] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.qmd"                             
#> [23] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.qpj"                             
#> [24] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.shp"                             
#> [25] "raw_data_cache/v2/zonificacion/zonificacion_distritos/zonificacion_distritos_centroides.shx"
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United Kingdom.utf8
#>  ctype    English_United Kingdom.utf8
#>  tz       Europe/London
#>  date     2024-09-07
#>  pandoc   3.2.1 @ C:/PROGRA~1/Pandoc/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version date (UTC) lib source
#>  bit             4.0.5   2022-11-15 [1] CRAN (R 4.4.1)
#>  bit64           4.0.5   2020-08-30 [1] CRAN (R 4.4.1)
#>  cachem          1.1.0   2024-05-16 [1] CRAN (R 4.4.1)
#>  class           7.3-22  2023-05-03 [2] CRAN (R 4.4.1)
#>  classInt        0.4-10  2023-09-05 [1] CRAN (R 4.4.1)
#>  cli             3.6.3   2024-06-21 [1] CRAN (R 4.4.1)
#>  crayon          1.5.3   2024-06-20 [1] CRAN (R 4.4.1)
#>  curl            5.2.2   2024-08-26 [1] CRAN (R 4.4.1)
#>  DBI             1.2.3   2024-06-02 [1] CRAN (R 4.4.1)
#>  dbplyr          2.5.0   2024-03-19 [1] CRAN (R 4.4.1)
#>  devtools        2.4.5   2022-10-11 [1] CRAN (R 4.4.1)
#>  digest          0.6.36  2024-06-23 [1] CRAN (R 4.4.1)
#>  dplyr           1.1.4   2023-11-17 [1] CRAN (R 4.4.1)
#>  duckdb          1.0.0-2 2024-07-19 [1] CRAN (R 4.4.1)
#>  e1071           1.7-14  2023-12-06 [1] CRAN (R 4.4.1)
#>  ellipsis        0.3.2   2021-04-29 [1] CRAN (R 4.4.1)
#>  evaluate        0.24.0  2024-06-10 [1] CRAN (R 4.4.1)
#>  fansi           1.0.6   2023-12-08 [1] CRAN (R 4.4.1)
#>  fastmap         1.2.0   2024-05-15 [1] CRAN (R 4.4.1)
#>  fs              1.6.4   2024-04-25 [1] CRAN (R 4.4.1)
#>  generics        0.1.3   2022-07-05 [1] CRAN (R 4.4.1)
#>  glue            1.7.0   2024-01-09 [1] CRAN (R 4.4.1)
#>  hms             1.1.3   2023-03-21 [1] CRAN (R 4.4.1)
#>  htmltools       0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)
#>  htmlwidgets     1.6.4   2023-12-06 [1] CRAN (R 4.4.1)
#>  httpuv          1.6.15  2024-03-26 [1] CRAN (R 4.4.1)
#>  KernSmooth      2.23-24 2024-05-17 [2] CRAN (R 4.4.1)
#>  knitr           1.48    2024-07-07 [1] CRAN (R 4.4.1)
#>  later           1.3.2   2023-12-06 [1] CRAN (R 4.4.1)
#>  lifecycle       1.0.4   2023-11-07 [1] CRAN (R 4.4.1)
#>  lubridate       1.9.3   2023-09-27 [1] CRAN (R 4.4.1)
#>  magrittr        2.0.3   2022-03-30 [1] CRAN (R 4.4.1)
#>  memoise         2.0.1   2021-11-26 [1] CRAN (R 4.4.1)
#>  memuse          4.2-3   2023-01-24 [1] CRAN (R 4.4.0)
#>  mime            0.12    2021-09-28 [1] CRAN (R 4.4.0)
#>  miniUI          0.1.1.1 2018-05-18 [1] CRAN (R 4.4.1)
#>  parallelly      1.38.0  2024-07-27 [1] CRAN (R 4.4.1)
#>  pillar          1.9.0   2023-03-22 [1] CRAN (R 4.4.1)
#>  pkgbuild        1.4.4   2024-03-17 [1] CRAN (R 4.4.1)
#>  pkgconfig       2.0.3   2019-09-22 [1] CRAN (R 4.4.1)
#>  pkgload         1.4.0   2024-06-28 [1] CRAN (R 4.4.1)
#>  profvis         0.3.8   2023-05-02 [1] CRAN (R 4.4.1)
#>  promises        1.3.0   2024-04-05 [1] CRAN (R 4.4.1)
#>  proxy           0.4-27  2022-06-09 [1] CRAN (R 4.4.1)
#>  purrr           1.0.2   2023-08-10 [1] CRAN (R 4.4.1)
#>  R.cache         0.16.0  2022-07-21 [1] CRAN (R 4.4.1)
#>  R.methodsS3     1.8.2   2022-06-13 [1] CRAN (R 4.4.0)
#>  R.oo            1.26.0  2024-01-24 [1] CRAN (R 4.4.0)
#>  R.utils         2.12.3  2023-11-18 [1] CRAN (R 4.4.1)
#>  R6              2.5.1   2021-08-19 [1] CRAN (R 4.4.1)
#>  Rcpp            1.0.13  2024-07-17 [1] CRAN (R 4.4.1)
#>  readr           2.1.5   2024-01-10 [1] CRAN (R 4.4.1)
#>  remotes         2.5.0   2024-03-17 [1] CRAN (R 4.4.1)
#>  reprex          2.1.0   2024-01-11 [1] CRAN (R 4.4.1)
#>  rlang           1.1.4   2024-06-04 [1] CRAN (R 4.4.1)
#>  rmarkdown       2.28    2024-08-17 [1] CRAN (R 4.4.1)
#>  sessioninfo     1.2.2   2021-12-06 [1] CRAN (R 4.4.1)
#>  sf              1.0-16  2024-03-24 [1] CRAN (R 4.4.1)
#>  shiny           1.8.1.1 2024-04-02 [1] CRAN (R 4.4.1)
#>  spanishoddata * 0.0.1   2024-09-07 [1] Github (ropenspain/spanishoddata@972ffa3)
#>  stringi         1.8.4   2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr         1.5.1   2023-11-14 [1] CRAN (R 4.4.1)
#>  styler          1.10.3  2024-04-07 [1] CRAN (R 4.4.1)
#>  tibble          3.2.1   2023-03-20 [1] CRAN (R 4.4.1)
#>  tidyselect      1.2.1   2024-03-11 [1] CRAN (R 4.4.1)
#>  timechange      0.3.0   2024-01-18 [1] CRAN (R 4.4.1)
#>  tzdb            0.4.0   2023-05-12 [1] CRAN (R 4.4.1)
#>  units           0.8-5   2023-11-28 [1] CRAN (R 4.4.1)
#>  urlchecker      1.0.1   2021-11-30 [1] CRAN (R 4.4.1)
#>  usethis         2.2.3   2024-02-19 [1] CRAN (R 4.4.1)
#>  utf8            1.2.4   2023-10-22 [1] CRAN (R 4.4.1)
#>  vctrs           0.6.5   2023-12-01 [1] CRAN (R 4.4.1)
#>  vroom           1.6.5   2023-12-05 [1] CRAN (R 4.4.1)
#>  withr           3.0.1   2024-07-31 [1] CRAN (R 4.4.1)
#>  xfun            0.45    2024-06-16 [1] CRAN (R 4.4.1)
#>  xml2            1.3.6   2023-12-04 [1] CRAN (R 4.4.1)
#>  xtable          1.8-4   2019-04-21 [1] CRAN (R 4.4.1)
#>  yaml            2.3.8   2023-12-11 [1] CRAN (R 4.4.0)
#> 
#>  [1] C:/Users/georl_admin/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2024-09-07 with reprex v2.1.0

Suggested fix: auto create the cache directory if it doesn't exist.

Context: split out from #70 (which is defo fixed btw, good job @e-kotov )!

@e-kotov
Copy link
Member

e-kotov commented Sep 7, 2024

Good catch! I was checking for this folder before the download, but apparently not before trying to list files in it, which comes before download )

@e-kotov e-kotov closed this as completed Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants