Skip to content

refactor: move {raster} and {terra} to Suggests #943

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented Mar 3, 2025

Follow-up to #942

I couldn't use the same approach because I didn't find the documentation in terra for automatic conversion raster -> terra like the useful sf::st_as_sf().

  • Avoid using {raster} in examples
  • Update CI to avoid deprecation warnings

@olivroy olivroy marked this pull request as ready for review March 3, 2025 19:06
@schloerke schloerke changed the title Replace raster with terra refactor: Replace {raster} with {terra} Mar 4, 2025
DESCRIPTION Outdated
rlang,
RColorBrewer,
scales (>= 1.0.0),
sf (>= 0.9-6),
stats,
terra (>= 1.6-3),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep {terra} as a Suggests? To me, it's similar to {hexbin} being suggested by {ggplot2}.

If a package w/ install difficulties is not critical path to the main package, I like to make the package a Suggest dependency when possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If so, this will require a few reverts to rlang::check_installed("terra")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's do this! Could you run revdep checks after merge? I could help if some revdeps are failing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you run revdep checks after merge?

Sure, np! I can also run it on this branch and push back results, if you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦
🏃

6 new problems. 1 seems like false-positive. The other 5 are related to sf or sp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a case for making PRs upstream if they are using outdated codes (as it's only a handful).

@olivroy olivroy changed the title refactor: Replace {raster} with {terra} refactor: move {raster} and {terra} to Suggests Mar 4, 2025
@jcheng5
Copy link
Member

jcheng5 commented Mar 5, 2025

I will leave the reviewing to @schloerke but I just wanted to say thank you, @olivroy, for these great contributions!

@olivroy olivroy requested a review from schloerke August 4, 2025 18:09
Copy link
Contributor

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivroy I'm guessing the revdepcheck errors came from #942 , not this PR.

I'm happy to merge this PR. But the revdep failures should be addressed before the next release.

@olivroy
Copy link
Contributor Author

olivroy commented Aug 5, 2025

sounds good to me! I will take a look

@schloerke
Copy link
Contributor

Larger revdepcheck result output

broken <- revdepcheck::cloud_broken()
broken_results <- revdepcheck::cloud_results() |> Filter(f = \(x) x$package %in% broken)
logs <-
    lapply(broken_results, \(info) info$cmp$output |> paste0(collapse = "\n")) |> 
    as.list() |> 
    setNames(vapply(broken_results, \(info) info$package[[1]], character(1)))

ignore <-
    Map(names(logs), logs, f = \(name, log) {
        cat(paste0("## ", name, "\n\n"))
        cat("```r\n")
        cat(log)
        cat("\n```\n\n")
    })

AtlasMaker

checking installed package size ... NOTE
  installed size is  6.7Mb
  sub-directories of 1Mb or more:
    data   6.5Mb
checking data for non-ASCII characters ... WARNING
  Error loading dataset 'amphibians':
   Error in .requirePackage(package) : unable to find required package 'sp'
  
  Error loading dataset 'birds':
   Error in .requirePackage(package) : unable to find required package 'sp'
  
  Error loading dataset 'flowering_plants':
   Error in .requirePackage(package) : unable to find required package 'sp'
  
  Error loading dataset 'reptiles':
   Error in .requirePackage(package) : unable to find required package 'sp'
  
  The dataset(s) may use package(s) not declared in Depends/Imports.
checking installed package size ... NOTE
  installed size is  6.7Mb
  sub-directories of 1Mb or more:
    data   6.5Mb

leafgl

checking tests ... ERROR
  Runningtestthat.RRunning the tests intests/testthat.Rfailed.
Complete output:
  > library(testthat)
  > library(leafgl)
  > 
  > test_check("leafgl")
  [ FAIL 3 | WARN 0 | SKIP 0 | PASS 370 ]
  
  ══ Failed tests ════════════════════════════════════════════════════════════════
  ── Error ('test-leafgl-addGlPolygons.R:26:3'): addGlPolygons works ─────────────
  Error in `asMethod(object)`: package sp required, please install it first
  Backtrace:1. └─methods::as(single_poly, "Spatial") at test-leafgl-addGlPolygons.R:26:3
   2.   └─sf (local) asMethod(object)
  ── Error ('test-leafgl-popup.R:507:3'): popup-lines-spatial ────────────────────
  <packageNotFoundError/error/condition>
  Error in `loadNamespace(x)`: there is no package called 'sp'
  Backtrace:1. ├─base::suppressWarnings(sf::as_Spatial(storms)) at test-leafgl-popup.R:507:3
   2. │ └─base::withCallingHandlers(...)
   3. ├─sf::as_Spatial(storms)
   4. └─base::loadNamespace(x)
   5.   └─base::withRestarts(stop(cond), retry_loadNamespace = function() NULL)
   6.     └─base (local) withOneRestart(expr, restarts[[1L]])
   7.       └─base (local) doWithOneRestart(return(expr), restart)
  ── Error ('test-leafgl-popup.R:721:3'): popup-polygon-spatial ──────────────────
  <packageNotFoundError/error/condition>
  Error in `loadNamespace(x)`: there is no package called 'sp'
  Backtrace:1. ├─base::suppressWarnings(sf::as_Spatial(gadm)) at test-leafgl-popup.R:721:3
   2. │ └─base::withCallingHandlers(...)
   3. ├─sf::as_Spatial(gadm)
   4. └─base::loadNamespace(x)
   5.   └─base::withRestarts(stop(cond), retry_loadNamespace = function() NULL)
   6.     └─base (local) withOneRestart(expr, restarts[[1L]])
   7.       └─base (local) doWithOneRestart(return(expr), restart)
  
  [ FAIL 3 | WARN 0 | SKIP 0 | PASS 370 ]
  Error: Test failures
  Execution halted

leaflet.extras2

checking tests ... ERROR
  Runningtestthat.RRunning the tests intests/testthat.Rfailed.
Complete output:
  > library(testthat)
  > library(htmltools)
  > library(leaflet)
  > library(leaflet.extras2)
  > 
  > test_check("leaflet.extras2")
  [ FAIL 1 | WARN 0 | SKIP 0 | PASS 440 ]
  
  ══ Failed tests ════════════════════════════════════════════════════════════════
  ── Error ('test-playback.R:355:3'): playback ───────────────────────────────────
  Error: unable to find an inherited method for function 'coordinates' for signature 'obj = "sf"'
  Backtrace:1. └─sp::coordinates(leaflet::atlStorms2005[1, ]) at test-playback.R:355:3
   2.   └─methods (local) `<fn>`(`<list>`, `<S4: standardGeneric>`, `<env>`)
  
  [ FAIL 1 | WARN 0 | SKIP 0 | PASS 440 ]
  Error: Test failures
  Execution halted

lingtypology

checking installed package size ... NOTE
  installed size is  7.7Mb
  sub-directories of 1Mb or more:
    data   6.5Mb
checking data for non-ASCII characters ... NOTE
  Note: found 60812 marked UTF-8 strings
checking tests ... ERROR
  Runningtestthat.RRunning the tests intests/testthat.Rfailed.
Complete output:
  > library(testthat)
  > library(lingtypology)
  Based on the Glottolog v. 5.2
  > 
  > test_check("lingtypology")
  [ FAIL 1 | WARN 0 | SKIP 34 | PASS 0 ]
  
  ══ Skipped tests (34) ══════════════════════════════════════════════════════════
  • On CRAN (34): 'test-abvd-feature.R:4:3', 'test-afbo-feature.R:5:3',
    'test-aff-lang.R:4:3', 'test-area-lang.R:7:3', 'test-bantu-feature.R:5:3',
    'test-country-lang.R:4:3', 'test-eurasianphonology-feature.R:5:3',
    'test-glottolog-database.R:5:3', 'test-glottolog-database.R:10:3',
    'test-gltc-iso.R:7:3', 'test-gltc-lang.R:7:3', 'test-grambank-feature.R:5:3',
    'test-iso-gltc.R:7:3', 'test-iso-lang.R:7:3', 'test-lang-aff.R:6:3',
    'test-lang-gltc.R:7:3', 'test-lang-iso.R:7:3', 'test-lat-lang.R:7:3',
    'test-level.lang.R:7:3', 'test-long-lang.R:7:3', 'test-mapfeature.R:8:3',
    'test-mapfeature.R:15:3', 'test-mapfeature.R:21:3', 'test-mapfeature.R:35:3',
    'test-mapfeature.R:83:3', 'test-mapfeature.R:93:3',
    'test-mapfeature.R:120:3', 'test-mapfeature.R:146:3',
    'test-sails-feature.R:5:3', 'test-soundcomparisons-feature.R:5:3',
    'test-subc-lang.R:4:3', 'test-url-lang.R:7:3', 'test-vanuatu-feature.R:5:3',
    'test-wals-feature.R:5:3'
  
  ══ Failed tests ════════════════════════════════════════════════════════════════
  ── Error ('test-mapfeature.R:161:1'): (code run outside of `test_that()`) ──────
  Error in `leaflet::addProviderTiles(leaflet::addTiles(m, tile[1]), tile[1], 
      group = tile.name[1], options = leaflet::providerTileOptions(opacity = tile.opacity))`: Unknown tile provider 'OpenStreetMap.BlackAndWhite'; either use a known provider or pass `check = FALSE` to `addProviderTiles()`
  Backtrace:1. └─lingtypology::map.feature(...) at test-mapfeature.R:161:1
   2.   └─leaflet::addProviderTiles(...)
  
  [ FAIL 1 | WARN 0 | SKIP 34 | PASS 0 ]
  Error: Test failures
  Execution halted
checking installed package size ... NOTE
  installed size is  7.7Mb
  sub-directories of 1Mb or more:
    data   6.5Mb
checking data for non-ASCII characters ... NOTE
  Note: found 60812 marked UTF-8 strings

mapview

checking data for non-ASCII characters ... NOTE
  Note: found 1 marked UTF-8 string
checking tests ... ERROR
  Runningtinytest.RRunning the tests intests/tinytest.Rfailed.
Complete output:
  > if (requireNamespace("tinytest", quietly=TRUE)) {
  +   tinytest::test_package("mapview")
  + }
  
  test-color.R..................    0 tests    
  test-color.R..................    1 tests OK 
  test-color.R..................    2 tests OK 
  test-color.R..................    3 tests OK 
  test-color.R..................    4 tests OK 
  test-color.R..................    5 tests OK 
  test-color.R..................    6 tests OK 53ms
  Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE
  
  test-mapview.R................    0 tests    
  test-mapview.R................    0 tests    
  test-mapview.R................    0 tests    
  test-mapview.R................    1 tests OK 
  test-mapview.R................    2 tests OK 
  test-mapview.R................    3 tests OK 
  test-mapview.R................    4 tests OK 
  test-mapview.R................    4 tests OK 
  test-mapview.R................    5 tests OK 
  test-mapview.R................    6 tests OK 
  test-mapview.R................    7 tests OK 
  test-mapview.R................    8 tests OK 
  test-mapview.R................    8 tests OK 
  test-mapview.R................    8 tests OK 
  test-mapview.R................    9 tests OK 
  test-mapview.R................   10 tests OK 
  test-mapview.R................   11 tests OK 
  test-mapview.R................   12 tests OK 
  test-mapview.R................   12 tests OK 
  test-mapview.R................   13 tests OK 
  test-mapview.R................   14 tests OK 
  test-mapview.R................   15 tests OK 
  test-mapview.R................   16 tests OK 
  test-mapview.R................   16 tests OK 
  test-mapview.R................   16 tests OK 
  test-mapview.R................   17 tests OK 
  test-mapview.R................   18 tests OK 
  test-mapview.R................   19 tests OK 
  test-mapview.R................   20 tests OK 
  test-mapview.R................   20 tests OK 
  test-mapview.R................   21 tests OK 
  test-mapview.R................   22 tests OK 
  test-mapview.R................   23 tests OK 
  test-mapview.R................   24 tests OK 
  test-mapview.R................   24 tests OK 
  test-mapview.R................   24 tests OK 
  test-mapview.R................   25 tests OK 
  test-mapview.R................   26 tests OK 
  test-mapview.R................   27 tests OK 
  test-mapview.R................   28 tests OK 
  test-mapview.R................   28 tests OK 
  test-mapview.R................   29 tests OK 
  test-mapview.R................   30 tests OK 
  test-mapview.R................   31 tests OK 
  test-mapview.R................   32 tests OK 
  test-mapview.R................   32 tests OK 
  test-mapview.R................   32 tests OK 
  test-mapview.R................   33 tests OK 
  test-mapview.R................   33 tests OK 
  test-mapview.R................   34 tests OK 
  test-mapview.R................   34 tests OK 
  test-mapview.R................   34 tests OK 
  test-mapview.R................   35 tests OK 
  test-mapview.R................   36 tests OK 
  test-mapview.R................   37 tests OK 
  test-mapview.R................   38 tests OK 
  test-mapview.R................   38 tests OK 
  test-mapview.R................   39 tests OK 
  test-mapview.R................   40 tests OK 
  test-mapview.R................   41 tests OK 
  test-mapview.R................   42 tests OK Loading required package: sp
  
  test-mapview.R................   42 tests OK 
  test-mapview.R................   42 tests OK 
  test-mapview.R................   43 tests OK 
  test-mapview.R................   44 tests OK 
  test-mapview.R................   45 tests OK 
  test-mapview.R................   46 tests OK 
  test-mapview.R................   46 tests OK 
  test-mapview.R................   47 tests OK 
  test-mapview.R................   48 tests OK 
  test-mapview.R................   49 tests OK 
  test-mapview.R................   50 tests OK 
  test-mapview.R................   50 tests OK 
  test-mapview.R................   50 tests OK 
  test-mapview.R................   51 tests OK 
  test-mapview.R................   52 tests OK 
  test-mapview.R................   53 tests OK 
  test-mapview.R................   54 tests OK 
  test-mapview.R................   54 tests OK 
  test-mapview.R................   55 tests OK 
  test-mapview.R................   56 tests OK 
  test-mapview.R................   57 tests OK 
  test-mapview.R................   58 tests OK 
  test-mapview.R................   58 tests OK 
  test-mapview.R................   59 tests OK 
  test-mapview.R................   60 tests OK 
  test-mapview.R................   61 tests OK 
  test-mapview.R................   62 tests OK 
  test-mapview.R................   62 tests OK 
  test-mapview.R................   63 tests OK 
  test-mapview.R................   64 tests OK 
  test-mapview.R................   65 tests OK 
  test-mapview.R................   66 tests OK 
  test-mapview.R................   66 tests OK 
  test-mapview.R................   67 tests OK 
  test-mapview.R................   68 tests OK 
  test-mapview.R................   69 tests OK 
  test-mapview.R................   70 tests OK 
  test-mapview.R................   70 tests OK 
  test-mapview.R................   71 tests OK 
  test-mapview.R................   72 tests OK 
  test-mapview.R................   73 tests OK 
  test-mapview.R................   74 tests OK 
  test-mapview.R................   74 tests OK 
  test-mapview.R................   75 tests OK 
  test-mapview.R................   76 tests OK 
  test-mapview.R................   77 tests OK 
  test-mapview.R................   78 tests OK 
  test-mapview.R................   78 tests OK 
  test-mapview.R................   79 tests OK 
  test-mapview.R................   80 tests OK 
  test-mapview.R................   81 tests OK 
  test-mapview.R................   82 tests OK 
  test-mapview.R................   82 tests OK 
  test-mapview.R................   82 tests OK 
  test-mapview.R................   83 tests OK 
  test-mapview.R................   84 tests OK 
  test-mapview.R................   85 tests OK 
  test-mapview.R................   86 tests OK 
  test-mapview.R................   86 tests OK 
  test-mapview.R................   87 tests OK 
  test-mapview.R................   88 tests OK 
  test-mapview.R................   89 tests OK 
  test-mapview.R................   90 tests OK 
  test-mapview.R................   90 tests OK 
  test-mapview.R................   91 tests OK 
  test-mapview.R................   92 tests OK 
  test-mapview.R................   93 tests OK 
  test-mapview.R................   94 tests OK 
  test-mapview.R................   94 tests OK 
  test-mapview.R................   95 tests OK 
  test-mapview.R................   96 tests OK 
  test-mapview.R................   97 tests OK 
  test-mapview.R................   98 tests OK 
  test-mapview.R................   98 tests OK 
  test-mapview.R................   99 tests OK 
  test-mapview.R................  100 tests OK 
  test-mapview.R................  101 tests OK 
  test-mapview.R................  102 tests OK 
  test-mapview.R................  102 tests OK 
  test-mapview.R................  103 tests OK 
  test-mapview.R................  104 tests OK 
  test-mapview.R................  105 tests OK 
  test-mapview.R................  106 tests OK 
  test-mapview.R................  106 tests OK 
  test-mapview.R................  106 tests OK 
  test-mapview.R................  107 tests OK 
  test-mapview.R................  108 tests OK 
  test-mapview.R................  109 tests OK 
  test-mapview.R................  110 tests OK 
  test-mapview.R................  110 tests OK 
  test-mapview.R................  111 tests OK 
  test-mapview.R................  112 tests OK 
  test-mapview.R................  113 tests OK 
  test-mapview.R................  114 tests OK 
  test-mapview.R................  114 tests OK 
  test-mapview.R................  114 tests OK 
  test-mapview.R................  115 tests OK 
  test-mapview.R................  116 tests OK 
  test-mapview.R................  117 tests OK 
  test-mapview.R................  118 tests OK 
  test-mapview.R................  118 tests OK 
  test-mapview.R................  119 tests OK 
  test-mapview.R................  120 tests OK 
  test-mapview.R................  121 tests OK 
  test-mapview.R................  122 tests OK 
  test-mapview.R................  122 tests OK 
  test-mapview.R................  122 tests OK Error in as(atlStorms2005, "SpatialLines") : 
    no method or default for coercing "sf" to "SpatialLines"
  Calls: <Anonymous> ... eval -> mapview -> standardGeneric -> eval -> eval -> as
  Execution halted
checking data for non-ASCII characters ... NOTE
  Note: found 1 marked UTF-8 string

rapr

checking tests ... ERROR
  Runningtinytest.RRunning the tests intests/tinytest.Rfailed.
Complete output:
  > 
  > if ( requireNamespace("tinytest", quietly=TRUE) ){
  +   tinytest::test_package("rapr")
  + }
  
  test_rapr.R...................    0 tests    
  test_rapr.R...................    0 tests    
  test_rapr.R...................    0 tests    
  test_rapr.R...................    0 tests    
  test_rapr.R...................    1 tests OK 
  test_rapr.R...................    2 tests OK 
  test_rapr.R...................    3 tests OK 
  test_rapr.R...................    3 tests OK 
  test_rapr.R...................    3 tests OK 
  test_rapr.R...................    4 tests OK 
  test_rapr.R...................    5 tests OK 
  test_rapr.R...................    6 tests OK 
  test_rapr.R...................    7 tests OK 
  test_rapr.R...................    7 tests OK Loading required namespace: sf
  
  test_rapr.R...................    7 tests OK 
  test_rapr.R...................    8 tests OK 
  test_rapr.R...................    9 tests OK 
  test_rapr.R...................   10 tests OK 
  test_rapr.R...................   10 tests OK 
  test_rapr.R...................   10 tests OK 
  test_rapr.R...................   11 tests OK 
  test_rapr.R...................   12 tests OK 
  test_rapr.R...................   13 tests OK 
  test_rapr.R...................   14 tests OK 
  test_rapr.R...................   14 tests OK Error in sfc2SpatialPolygons(from, IDs) : 
    package sp required, please install it first
  Calls: <Anonymous> ... <Anonymous> -> as_Spatial -> .as_Spatial -> sfc2SpatialPolygons
  Execution halted

@schloerke
Copy link
Contributor

One article to fix before merge. Thank you, @olivroy !

2025-08-05T04:01:05.0930571Z Reading vignettes/articles/projections.Rmd
2025-08-05T04:01:06.7633298Z Error in `.f()`:
2025-08-05T04:01:06.7633851Z ! Failed to render 'vignettes/articles/projections.Rmd'.
2025-08-05T04:01:06.7634731Z ✖ Quitting from projections.Rmd:81-110 [unnamed-chunk-6]
2025-08-05T04:01:06.7635184Z Caused by error:
2025-08-05T04:01:06.7635623Z ! `x` must be a vector, not a <sfc_MULTIPOLYGON/sfc> object.
2025-08-05T04:01:06.7636463Z Backtrace:
2025-08-05T04:01:06.7636722Z      ▆
2025-08-05T04:01:06.7637452Z   1. ├─dplyr::filter(rnaturalearth::countries110, CONTINENT == "North America")
2025-08-05T04:01:06.7638127Z   2. ├─dplyr:::filter.data.frame(...)
2025-08-05T04:01:06.7639028Z   3. │ ├─dplyr::dplyr_row_slice(.data, loc, preserve = .preserve)
2025-08-05T04:01:06.7641915Z   4. │ └─dplyr:::dplyr_row_slice.data.frame(.data, loc, preserve = .preserve)
2025-08-05T04:01:06.7643061Z   5. │   ├─dplyr::dplyr_reconstruct(vec_slice(data, i), data)
2025-08-05T04:01:06.7643861Z   6. │   │ └─dplyr:::dplyr_new_data_frame(data)
2025-08-05T04:01:06.7645094Z   7. │   │   ├─row.names %||% .row_names_info(x, type = 0L)
2025-08-05T04:01:06.7645950Z   8. │   │   └─base::.row_names_info(x, type = 0L)
2025-08-05T04:01:06.7646623Z   9. │   └─vctrs::vec_slice(data, i)
2025-08-05T04:01:06.7647474Z  10. └─vctrs:::stop_scalar_type(`<fn>`(`<s_MULTIP>`), "x", `<fn>`(vec_size()))
2025-08-05T04:01:06.7648638Z  11.   └─vctrs:::stop_vctrs(...)
2025-08-05T04:01:06.7649752Z  12.     └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

@olivroy
Copy link
Contributor Author

olivroy commented Aug 5, 2025

It seems that the problem lied in the fact that filter.sf() method was not loaded. Loading the sf package fixes this!

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 this pull request may close these issues.

3 participants