Skip to content

Commit

Permalink
Add new features (#104)
Browse files Browse the repository at this point in the history
* Add new FAQ

* First stub

* Fix external package

* Start preparing new version

* Update docs with pkgdev

* Update FAQs

* Improve funs

* tests and checks

* Update tests and functions

* Update docs with pkgdev

* Add tests

* Documentation

* Add test for keeping coltabs

* Add more tests

* Fix tests

* Add snapshots

* Update docs with pkgdev

* Create wipe-cache.yaml

* revdepcheck

* Small typo

* Rebuild docs

* revdepcheck

* Enhance glimpse

* Complete glimpse

* Update docs with pkgdev

* Improve printing

* Improve glimpse

* Update up to autoplot

* Update all but plotting funs

* Continue migrating

* Update template

* Fix references

* Add authors

* Delete extra

* Rebase test_cli (#100)

* Update template

* Fix references

* Add authors

* Update docs with pkgdev

* End cli migration

* Add auto dev

* Update docs with pkgdev

* revdepcheck

* revdepcheck

* Update docs with pkgdev

* Add more references

* Update docs with pkgdev

* Update pkgdown , etc.

* Update docs with pkgdev

* Add In the wild article

* Improve docs

* Add more pubs

* Add more references

* Add j lacko

* Update docs with pkgdev

* Add new article

* Fix citation

* Add more

* Start cleaning

* [ImgBot] Optimize images

*Total -- 5,967.86kb -> 5,739.73kb (3.82%)

/vignettes/lux_ggplot-1.png -- 55.04kb -> 45.03kb (18.19%)
/vignettes/contourfilled-1.png -- 76.71kb -> 63.99kb (16.59%)
/vignettes/aggregate-2.png -- 50.62kb -> 42.62kb (15.8%)
/vignettes/aggregate-1.png -- 38.90kb -> 33.88kb (12.9%)
/img/README-spatvec-1.png -- 171.66kb -> 151.26kb (11.88%)
/img/README-hypso-1.png -- 227.49kb -> 201.32kb (11.51%)
/img/README-example-tile-2.png -- 1,841.75kb -> 1,780.17kb (3.34%)
/img/README-example-tile-1.png -- 1,342.09kb -> 1,301.47kb (3.03%)
/vignettes/spatraster-example-1.png -- 165.34kb -> 160.38kb (3%)
/img/spatraster-example-1.png -- 165.34kb -> 160.38kb (3%)
/img/README-example-temp-1.png -- 165.34kb -> 160.38kb (3%)
/vignettes/faceted-1.png -- 45.08kb -> 43.93kb (2.56%)
/vignettes/contourlines-1.png -- 206.18kb -> 201.09kb (2.47%)
/img/README-hypso-2.png -- 327.35kb -> 319.85kb (2.29%)
/img/README-example-temp-2.png -- 245.70kb -> 240.50kb (2.11%)
/vignettes/rgb-1.png -- 287.13kb -> 282.81kb (1.51%)
/vignettes/rgb-2.png -- 348.19kb -> 344.54kb (1.05%)
/vignettes/hypso-1.png -- 207.95kb -> 206.11kb (0.89%)

Signed-off-by: ImgBotApp <[email protected]>

* Update codefactor

* Update docs with pkgdev

* Improve codefactor and lint

* Dedupe badges

* Improve docs

* Update docs with pkgdev

* Add examples and references

* Add new reference

* Update snapshots as they changed due to new version of testthat

* Make get_coltab_pal robust when layers does not have a unique name

* Update tests and R local version

* Add JOSS data

* Update docs with pkgdev

* Update issn and header

* Update docs with pkgdev

---------

Signed-off-by: ImgBotApp <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Diego H <[email protected]>
Co-authored-by: Enrico Spinielli <[email protected]>
Co-authored-by: ImgBotApp <[email protected]>
  • Loading branch information
5 people authored Nov 10, 2023
1 parent f220de6 commit 6d868b6
Show file tree
Hide file tree
Showing 278 changed files with 18,314 additions and 2,054 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pkgdown-gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
local::.
any::pkgdown
any::metR
Nowosad/spDataLarge
needs: website

- name: Deploy package
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/update-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ jobs:
any::rcmdcheck
any::pkgdown
any::metR
Nowosad/spDataLarge
dieghernan/pkgdev
needs: website

- name: Update docs
run: |
pkgdev::precompute_vignette_all()
# pkgdev::precompute_vignette_all()
pkgdev::update_docs(precompute = FALSE)
shell: Rscript {0}
Expand Down
35 changes: 19 additions & 16 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ message: 'To cite package "tidyterra" in publications use:'
type: software
license: MIT
title: 'tidyterra: ''tidyverse'' Methods and ''ggplot2'' Helpers for ''terra'' Objects'
version: 0.4.1
doi: 10.5281/zenodo.6572471
version: 0.4.1.9000
doi: 10.21105/joss.05751
abstract: Extension of the 'tidyverse' for 'SpatRaster' and 'SpatVector' objects of
the 'terra' package. It includes also new 'geom_' functions that provide a convenient
way of visualizing 'terra' objects with 'ggplot2'.
Expand All @@ -19,20 +19,23 @@ authors:
email: [email protected]
orcid: https://orcid.org/0000-0001-8457-4658
preferred-citation:
type: manual
type: article
title: 'Using the tidyverse with terra objects: the tidyterra package'
authors:
- family-names: Hernangómez
given-names: Diego
email: [email protected]
orcid: https://orcid.org/0000-0001-8457-4658
doi: 10.5281/zenodo.6572471
doi: 10.21105/joss.05751
year: '2023'
version: 0.4.1
url: https://dieghernan.github.io/tidyterra/
abstract: Extension of the tidyverse for SpatRaster and SpatVector objects of the
terra package. It includes also new geom_ functions that provide a convenient
way of visualizing terra objects with ggplot2.
url: https://doi.org/10.21105/joss.05751
publisher:
name: The Open Journal
volume: '8'
issue: '91'
journal: Journal of Open Source Software
issn: 2475-9066
start: '5751'
repository: https://CRAN.R-project.org/package=tidyterra
repository-code: https://github.com/dieghernan/tidyterra
url: https://dieghernan.github.io/tidyterra/
Expand All @@ -42,16 +45,16 @@ contact:
email: [email protected]
orcid: https://orcid.org/0000-0001-8457-4658
keywords:
- cran
- cran-r
- ggplot-extension
- r
- r-package
- terra
- ggplot-extension
- r-spatial
- rspatial
- cran
- cran-r
- r-package
- rstats
- rstats-package
- terra
references:
- type: software
title: 'R: A Language and Environment for Statistical Computing'
Expand Down Expand Up @@ -294,10 +297,10 @@ references:
authors:
- family-names: Henry
given-names: Lionel
email: lionel@rstudio.com
email: lionel@posit.co
- family-names: Wickham
given-names: Hadley
email: hadley@rstudio.com
email: hadley@posit.co
orcid: https://orcid.org/0000-0003-4757-117X
year: '2023'
- type: software
Expand Down
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tidyterra
Title: 'tidyverse' Methods and 'ggplot2' Helpers for 'terra' Objects
Version: 0.4.1
Version: 0.4.1.9000
Authors@R: c(
person("Diego", "Hernangómez", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8457-4658")),
Expand Down Expand Up @@ -43,10 +43,12 @@ Suggests:
VignetteBuilder:
knitr
Config/Needs/coverage: covr
Config/Needs/website: geodata, metR, dieghernan/gitdevr, ragg, styler
Config/Needs/website: geodata, metR, dieghernan/gitdevr, ragg, styler,
Nowosad/spDataLarge, ggspatial
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
X-schema.org-keywords: r, terra, ggplot-extension, r-spatial, rspatial
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export(geom_spatraster_rgb)
export(geom_spatvector)
export(geom_spatvector_label)
export(geom_spatvector_text)
export(get_coltab_pal)
export(glimpse)
export(group_by)
export(group_by_drop_default)
Expand All @@ -123,6 +124,7 @@ export(rename_with)
export(replace_na)
export(right_join)
export(rowwise)
export(scale_color_coltab)
export(scale_color_cross_blended_b)
export(scale_color_cross_blended_c)
export(scale_color_cross_blended_d)
Expand All @@ -144,6 +146,7 @@ export(scale_color_whitebox_d)
export(scale_color_wiki_b)
export(scale_color_wiki_c)
export(scale_color_wiki_d)
export(scale_colour_coltab)
export(scale_colour_cross_blended_b)
export(scale_colour_cross_blended_c)
export(scale_colour_cross_blended_d)
Expand All @@ -165,6 +168,7 @@ export(scale_colour_whitebox_d)
export(scale_colour_wiki_b)
export(scale_colour_wiki_c)
export(scale_colour_wiki_d)
export(scale_fill_coltab)
export(scale_fill_cross_blended_b)
export(scale_fill_cross_blended_c)
export(scale_fill_cross_blended_d)
Expand Down Expand Up @@ -207,6 +211,7 @@ export(transmute)
export(ungroup)
export(whitebox.colors)
export(wiki.colors)
importFrom(cli,qty)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
importFrom(dplyr,count)
Expand Down Expand Up @@ -252,6 +257,7 @@ importFrom(ggplot2,after_stat)
importFrom(ggplot2,alpha)
importFrom(ggplot2,autoplot)
importFrom(ggplot2,fortify)
importFrom(grDevices,col2rgb)
importFrom(grDevices,rgb)
importFrom(grDevices,terrain.colors)
importFrom(magrittr,"%>%")
Expand Down
17 changes: 16 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# tidyterra (development version)

- Support for SpatRasters with a color table
- `autoplot.SpatRaster()` can detect now SpatRasters with color tables.
- `geom_spatraster()` can detect now SpatRasters with color tables.
- New scales for plotting SpatRasters with color tables:
`scale_fill_coltab()` and rest of family scales (`colour`).
- tidyverse verbs keeps the associated `coltab` of a SpatRaster.
- By default all the discrete scales of tidyterra now have the following
setup: `na.translate = FALSE`.
- Enhanced `glimpse.Spat()` with meta-information on type of geometry, crs,
etc.
- New messaging interface thanks to [**cli**](https://cli.r-lib.org/) package.
- Update citation.

# tidyterra 0.4.1

- Release for JOSS paper. No relevant changes.
Expand Down Expand Up @@ -47,7 +62,7 @@
`"meyers"` and `"nordisk-familjebok"`.
- Added colour scales to all palettes: `scale_colour_*`.
- Remove use of `ggplot2::aes_string()`.
- Adapt geom\_`spatraster_contour()` and `geom_spatraster_contour_filled()` to
- Adapt `geom_spatraster_contour()` and `geom_spatraster_contour_filled()` to
the changes introduced in **ggplot2 (3.4.0)**, most notably the adoption of
`linewidth = .2`, by default.

Expand Down
5 changes: 4 additions & 1 deletion R/as_coordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#'
as_coordinates <- function(x, as.raster = FALSE) {

Check warning on line 37 in R/as_coordinates.R

View workflow job for this annotation

GitHub Actions / Run lintr scanning

file=R/as_coordinates.R,line=37,col=31,[object_name_linter] Variable and function name style should match snake_case or symbols.
if (!inherits(x, "SpatRaster")) {
stop("as_coordinates() needs a SpatRaster object")
cli::cli_abort(paste(
"{.fun tidyterra::as_coordinates} needs a {.cls SpatRaster} object,",
"not a {.cls {class(x)}} object"
))
}

# Create skeleton
Expand Down
5 changes: 3 additions & 2 deletions R/as_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
#' group_data(a_gr_sf)
#'
as_sf <- function(x, ...) {
if (!inherits(x, "SpatVector")) cli::cli_abort("x is not a SpatVector")

if (!inherits(x, "SpatVector")) {
cli::cli_abort("{.arg x} is a {.cls {class(x)}} not a {.cls SpatVector}")
}
sfobj <- sf::st_as_sf(x, ...)

if (is_grouped_spatvector(x)) {
Expand Down
18 changes: 13 additions & 5 deletions R/as_spatraster.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,23 @@ as_spatraster <- function(x, ..., xycols = 1:2, crs = "", digits = 6) {
# Create from dtplyr
if (inherits(x, "dtplyr_step")) x <- tibble::as_tibble(x)


if (!inherits(x, "data.frame")) {
cli::cli_abort(
"x should be a data.frame/tibble"
"{.arg x} should be a {.cls data.frame/tbl}, not {.cls {class(x)}}"
)
}

if (length(xycols) != 2 || !is.numeric(xycols)) {
stop("xycols should be two integers: `c(int, int)`")
if (length(xycols) != 2) {
cli::cli_abort(paste(
"{.arg xycols} should have a length of {.val {as.integer(2)}},",
"not {.val {length(xycols)}}"
))
}

if (!is.numeric(xycols)) {
cli::cli_abort(
"{.arg xycols} should be a {.cls integer}, not {.cls {class(xycols)}}"
)
}

xycols <- as.integer(xycols)
Expand Down Expand Up @@ -127,7 +135,7 @@ as_spatraster <- function(x, ..., xycols = 1:2, crs = "", digits = 6) {
xyvalind$valindex <- seq_len(nrow(xyvalind))


values_w_ind <- x_arrange[, -c(1:2)]
values_w_ind <- x_arrange[, -c(1, 2)]
values_w_ind$valindex <- xyvalind$valindex


Expand Down
22 changes: 13 additions & 9 deletions R/as_spatvector.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ as_spatvector <- function(x, ...) {
#' @export
as_spatvector.data.frame <- function(x, ..., geom = c("lon", "lat"), crs = "") {
if (!length(geom) %in% c(1, 2)) {
stop("geom should be of lenght 1 or 2")
cli::cli_abort(paste(
"{.arg geom} should be of length {.val {as.integer(1)}} or",
"{.val {as.integer(2)}}, not {.val {length(geom)}}"
))
}

if (!is.character(geom)) {
stop("geom should be of type <character>")
cli::cli_abort(paste(
"{.arg geom} should be a {.cls character}, not",
"{.cls {class(geom)}}"
))
}

if (!all(geom %in% names(x))) {
stop(
paste0("Column(s) <", paste0(setdiff(geom, names(x)), collapse = ",")),
"> not found in x"
cli::cli_abort(
"Column{?s} {.var {setdiff(geom, names(x))}} not found in {.arg x}"
)
}

Expand All @@ -109,10 +114,9 @@ as_spatvector.data.frame <- function(x, ..., geom = c("lon", "lat"), crs = "") {
tbl_end <- tidyr::drop_na(tbl, dplyr::all_of(geom))

if (nrow(tbl) != nrow(tbl_end)) {
message(paste0(
"Removed ", nrow(tbl) - nrow(tbl_end),
" row(s) with empty geom column(s) <",
paste0(geom, collapse = ","), ">"
cli::cli_alert_warning(paste(
"Removed {nrow(tbl) - nrow(tbl_end)} row{?s} with empty",
"{.arg geom}{qty({length(geom)})} column{?s} {.val {geom}}"
))
}

Expand Down
40 changes: 20 additions & 20 deletions R/as_tibble-Spat.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ as_tibble.SpatVector <- function(x, ..., geom = NULL, .name_repair = "unique") {

as_tbl_internal <- function(x) {
if (!inherits(x, c("SpatRaster", "SpatVector"))) {
cli::cli_abort("x is not a Spat* object")
cli::cli_abort(
"{.arg x} is not of {.cls SpatRaster} or {.cls SpatVector} object"
)
}

if (inherits(x, "SpatRaster")) {
Expand Down Expand Up @@ -255,36 +257,34 @@ make_safe_names <- function(x, geom = NULL, messages = TRUE) {
cli::cli_alert_info(paste(
for_message,
"with duplicated/reserved names detected.",
"See `About layer/column names` section on",
"`?as_tibble.SpatRaster`", "\n"
))
"See {.strong About layer/column names} section on",
"{.fun tidyterra::as_tibble.SpatRaster}"
), wrap = TRUE)
cli::cli_alert_warning("Renaming columns:")
}
if (geom == "XY") {
names_with_coords <- c("x", "y", init_names)
# Make new names
newnames <- make.names(names_with_coords, unique = TRUE)

newnames <- newnames[-c(1:2)]
newnames <- newnames[-c(1, 2)]
} else {
names_with_coords <- c("geometry", init_names)
# Make new names
newnames <- make.names(names_with_coords, unique = TRUE)

newnames <- newnames[-c(1)]
newnames <- newnames[-1]
}
# Make new names
if (messages) {
names_changed <- !newnames == init_names

message(cli::col_black("New column names:"))
message(cli::col_black(
paste0("`", init_names[names_changed], "` -> `",
newnames[names_changed], "`",
collapse = "\n"
)
))
message(cli::col_black("\n"))
msg <- paste0(
"`", init_names[names_changed], "` -> `",
newnames[names_changed], "`"
)

cli::cat_bullet(msg)
}
names(x) <- newnames
return(x)
Expand All @@ -308,10 +308,10 @@ check_regroups <- function(x) {

if (isFALSE(any_var)) {
cli::cli_alert_warning(paste(
"`group_vars()` missing on data.",
" Have you mixed terra and tidyterra syntax?"
"{.fun tidyterra::group_vars.SpatVector} missing on data.",
" Have you mixed {.pkg terra} and {.pkg tidyterra} syntax?"
))
cli::cli_bullets(c(i = "ungrouping data"))
cli::cli_bullets(c(i = "Ungrouping data"))
return(dplyr::ungroup(x))
}

Expand Down Expand Up @@ -359,10 +359,10 @@ check_regroups <- function(x) {

if (isFALSE(any_var)) {
cli::cli_alert_warning(paste(
"`group_vars()` missing on data.",
" Have you mixed terra and tidyterra syntax?"
"{.fun tidyterra::group_vars.SpatVector} missing on data.",
" Have you mixed {.pkg terra} and {.pkg tidyterra} syntax?"
))
cli::cli_bullets(c(i = "ungrouping data"))
cli::cli_bullets(c(i = "Ungrouping data"))
return(dplyr::ungroup(x))
}

Expand Down
Loading

0 comments on commit 6d868b6

Please sign in to comment.