Skip to content

Commit

Permalink
changed startup message to onattach and defaulted back to default rhu…
Browse files Browse the repository at this point in the history
…b check
  • Loading branch information
datapumpernickel committed May 23, 2024
1 parent 15b0424 commit ba076bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ jobs:
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
env:
_R_CHECK_THINGS_IN_OTHER_DIRS_: true

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
Expand Down Expand Up @@ -94,5 +93,3 @@ jobs:
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
env:
_R_CHECK_THINGS_IN_OTHER_DIRS_: true
44 changes: 27 additions & 17 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ assign(
envir = ct_env
)

.onAttach <- function(libname, pkgname) {
## throw a warning, if a cache in the non-compliant directory is detected
## but only if there is actually any files in this directory
## pointing to the migrating function
if ((
rappdirs::user_cache_dir('comtradr') !=
tools::R_user_dir('comtradr', which = 'cache')
) &&
(length(list.files(rappdirs::user_cache_dir('comtradr'))) > 0 |
length(list.files(
rappdirs::user_cache_dir('comtradr_bulk')
)) > 0)) {
packageStartupMessage(cli::cli_bullets(
c(
"In the last version of comtradr the cache location has been changed, because it was not CRAN compliant. You can:", #nolint
'*' = 'Migrate the cache and clean old files with {.run ct_migrate_cache()}',
'*' = 'Ignore this warning, a new cache is created automatically.',
'*' = "Delete your old cache manually with:",
'*' = "{.run rappdirs::user_cache_dir('comtradr') |> list.files(full.names = T) |> file.remove()}", #nolint
' ' = "and",
'*' = "{.run rappdirs::user_cache_dir('comtradr_bulk') |> list.files(full.names = T) |> file.remove()}") #nolint
))
}
}



.onLoad <- function(libname, pkgname) {
max_size_env <- Sys.getenv("COMTRADR_CACHE_MAX_SIZE")
Expand Down Expand Up @@ -47,23 +73,7 @@ assign(
value = cache,
envir = rlang::ns_env("comtradr"))

## throw a warning, if a cache in the non-compliant directory is detected
## but only if there is actually any files in this directory
## pointing to the migrating function
if(
(rappdirs::user_cache_dir('comtradr')!=
tools::R_user_dir('comtradr', which = 'cache')) &&
(length(list.files(rappdirs::user_cache_dir('comtradr')))>0|
length(list.files(rappdirs::user_cache_dir('comtradr_bulk')))>0)){
cli::cli_bullets(c("In the last version of comtradr the cache location has been changed, because it was not CRAN compliant. You can:", #nolint
'*' = 'Migrate the cache and clean old files with {.run ct_migrate_cache()}',
'*' = 'Ignore this warning, a new cache is created automatically.',
'*' = "Delete your old cache manually with:",
'*' = "{.run rappdirs::user_cache_dir('comtradr') |> list.files(full.names = T) |> file.remove()}", #nolint
' ' = "and",
'*' = "{.run rappdirs::user_cache_dir('comtradr_bulk') |> list.files(full.names = T) |> file.remove()}") #nolint
)
}


}

Expand Down

0 comments on commit ba076bf

Please sign in to comment.