Skip to content

Commit

Permalink
refactor: turn data frames into tibbles for readability via attr()
Browse files Browse the repository at this point in the history
  • Loading branch information
salvafern committed Feb 23, 2024
1 parent 3e1e20b commit c3d4690
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 70 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ Imports:
Suggests:
testthat (>= 3.0.0),
mapview,
dplyr,
tibble
dplyr
Remotes:
eblondel/ows4R
RoxygenNote: 7.2.0
Expand Down
2 changes: 2 additions & 0 deletions R/eurobis_occurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,7 @@ eurobis_sf_df_handler <- function(sf_df){

sf::st_crs(sf_df) <- 4326

try({ attr(sf_df, "class") <- c("sf", "tbl_df", "tbl", "data.frame") })

return(sf_df)
}
11 changes: 5 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
output: github_document
df_print: "tibble"
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down Expand Up @@ -54,8 +55,7 @@ A basic example is:
library(eurobis)
# Get one single dataset
dataset <- eurobis_occurrences_basic(dasid = 8045)
dplyr::glimpse(dataset)
eurobis_occurrences_basic(dasid = 8045)
```

For detailed information run:
Expand All @@ -67,16 +67,15 @@ help(eurobis_occurrences)
## Query by traits
Use the `functional_group` argument:

```{r func_groups}
```{r func_groups, eval = FALSE}
# Get one single dataset
dataset <- eurobis_occurrences_basic(dasid = 8045, functional_groups = "angiosperms")
dplyr::glimpse(dataset)
eurobis_occurrences_basic(dasid = 8045, functional_groups = "angiosperms")
```

See the full list of queriable traits in the exported dataset `species_traits`:

```{r traits}
tibble::as_tibble(species_traits)
species_traits
```


Expand Down
195 changes: 136 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ The `eurobis` R package allows you to download data from EurOBIS.

You can query on:

- **Dataset**: provide the Integrated Marine Information System
- **Dataset**: provide the Integrated Marine Information System
([IMIS](https://www.vliz.be/en/integrated-marine-information-system))
unique identifier for datasets
[DasID](https://www.vliz.be/imis?page=webservices).
- **Taxon**: use a scientific name (e.g. the sea turtle *Caretta
- **Taxon**: use a scientific name (e.g. the sea turtle *Caretta
caretta*) or a [WoRMS
AphiaID](https://www.marinespecies.org/about.php#what_is_aphia)
(e.g. [137205](https://www.marinespecies.org/aphia.php?p=taxdetails&id=137205))
- **Traits**: get all occurrences that are benthos. Or zooplankton. Or
- **Traits**: get all occurrences that are benthos. Or zooplankton. Or
both. Powered by [WoRMS](https://www.marinespecies.org/).
- **Time**: just give start and end dates.
- **Geographically**: it allows to query on more than 300 records from
- **Time**: just give start and end dates.
- **Geographically**: it allows to query on more than 300 records from
the [Marine Regions
Gazetteer](https://marineregions.org/gazetteer.php) by giving the
[MRGID](https://marineregions.org/mrgid.php). Or just pass the area
of your interest as a polygon written in as [Well Known
Text](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)
- Other important classifications as [IUCN Red
- Other important classifications as [IUCN Red
List](https://www.iucnredlist.org/en), [MSDF
Indicators](https://msfd.eu/knowseas/guidelines/3-INDICATORS-Guideline.pdf)
or [Habitats
Expand Down Expand Up @@ -61,25 +61,35 @@ A basic example is:
library(eurobis)

# Get one single dataset
dataset <- eurobis_occurrences_basic(dasid = 8045)
eurobis_occurrences_basic(dasid = 8045)
#> Loading ISO 19139 XML schemas...
#> Loading ISO 19115 codelists...
#> Loading IANA mime types...
#> No encoding supplied: defaulting to UTF-8.
#> ✔ Downloading layer: EMODnet EurOBIS Basic Occurrence Data
#> ℹ The Basic Occurrence Data download provides you data for the following 8 essential terms: datasetid, datecollected, decimallongitude, decimallatitude, coordinateuncertaintyinmeters, scientificname, aphiaid, scientificnameaccepted. For more information, please consult: https://www.emodnet-biology.eu/emodnet-data-format.
dplyr::glimpse(dataset)
#> Rows: 52
#> Columns: 11
#> $ gml_id <chr> "eurobis-obisenv_basic.fid-632d47d4_1860…
#> $ id <int> 28840495, 28841810, 28837086, 28866685, …
#> $ datasetid <chr> "http://www.emodnet-biology.eu/data-cata…
#> $ datecollected <dttm> 2020-03-03 01:00:00, 2020-05-05 02:00:0…
#> $ decimallongitude <dbl> -8.73914, -8.73948, -8.73902, -8.73948, …
#> $ decimallatitude <dbl> 40.61804, 40.61899, 40.61773, 40.61899, …
#> $ coordinateuncertaintyinmeters <dbl> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5…
#> $ scientificname <chr> "Zostera marina", "Zostera marina", "Zos…
#> $ aphiaid <chr> "http://marinespecies.org/aphia.php?p=ta…
#> $ scientificnameaccepted <chr> "Zostera subg. Zostera marina", "Zostera…
#> $ geometry <POINT [°]> POINT (-8.73914 40.61804), POINT (…
#> Simple feature collection with 52 features and 10 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -8.73964 ymin: 40.61773 xmax: -8.73902 ymax: 40.61899
#> CRS: EPSG:4326
#> # A tibble: 52 × 11
#> gml_id id datas…¹ datecollected decim…² decim…³ coord…⁴ scien…⁵
#> * <fct> <int> <chr> <dttm> <dbl> <dbl> <dbl> <chr>
#> 1 eurobis-o… 3.68e7 https:… 2020-05-05 00:00:00 -8.74 40.6 5 Zoster…
#> 2 eurobis-o… 3.68e7 https:… 2019-12-13 00:00:00 -8.74 40.6 5 Zoster…
#> 3 eurobis-o… 3.68e7 https:… 2020-03-03 00:00:00 -8.74 40.6 5 Zoster…
#> 4 eurobis-o… 3.68e7 https:… 2019-12-13 00:00:00 -8.74 40.6 5 Zoster…
#> 5 eurobis-o… 3.68e7 https:… 2020-08-10 00:00:00 -8.74 40.6 5 Zoster…
#> 6 eurobis-o… 3.68e7 https:… 2020-08-10 00:00:00 -8.74 40.6 5 Zoster…
#> 7 eurobis-o… 3.68e7 https:… 2020-05-05 00:00:00 -8.74 40.6 5 Zoster…
#> 8 eurobis-o… 3.68e7 https:… 2020-05-05 00:00:00 -8.74 40.6 5 Zoster…
#> 9 eurobis-o… 3.68e7 https:… 2020-03-03 00:00:00 -8.74 40.6 5 Zoster…
#> 10 eurobis-o… 3.68e7 https:… 2020-05-05 00:00:00 -8.74 40.6 5 Zoster…
#> # … with 42 more rows, 3 more variables: aphiaid <chr>,
#> # scientificnameaccepted <chr>, geometry <POINT [°]>, and abbreviated
#> # variable names ¹​datasetid, ²​decimallongitude, ³​decimallatitude,
#> # ⁴​coordinateuncertaintyinmeters, ⁵​scientificname
```

For detailed information run:
Expand All @@ -94,46 +104,113 @@ Use the `functional_group` argument:

``` r
# Get one single dataset
dataset <- eurobis_occurrences_basic(dasid = 8045, functional_groups = "angiosperms")
#> ✔ Downloading layer: EMODnet EurOBIS Basic Occurrence Data
#> ℹ The Basic Occurrence Data download provides you data for the following 8 essential terms: datasetid, datecollected, decimallongitude, decimallatitude, coordinateuncertaintyinmeters, scientificname, aphiaid, scientificnameaccepted. For more information, please consult: https://www.emodnet-biology.eu/emodnet-data-format.
#> Warning in eurobis_occurrences(type = "basic", ...): There are 0 occurrences in
#> EurOBIS for this query at the moment
dplyr::glimpse(dataset)
#> Rows: 0
#> Columns: 11
#> $ gml_id <chr>
#> $ id <int>
#> $ datasetid <chr>
#> $ datecollected <dttm>
#> $ decimallongitude <dbl>
#> $ decimallatitude <dbl>
#> $ coordinateuncertaintyinmeters <dbl>
#> $ scientificname <chr>
#> $ aphiaid <chr>
#> $ scientificnameaccepted <chr>
#> $ geometry <GEOMETRY [°]>
eurobis_occurrences_basic(dasid = 8045, functional_groups = "angiosperms")
```

See the full list of queriable traits in the exported dataset
`species_traits`:

``` r
tibble::as_tibble(species_traits)
#> # A tibble: 32 × 4
#> category group selection selectid
#> <chr> <chr> <chr> <chr>
#> 1 Species group Functional group algae Algae
#> 2 Species group Functional group angiosperms Angiosperms
#> 3 Species group Functional group benthos Benthos
#> 4 Species group Functional group birds Birds
#> 5 Species group Functional group mammals Mammals
#> 6 Species group Functional group phytoplankton phytoplankton
#> 7 Species group Functional group pisces pisces
#> 8 Species group Functional group reptiles Reptiles
#> 9 Species group Functional group zooplankton zooplankton
#> 10 Species importance to society CITES Annex I 28_280_0
#> # … with 22 more rows
species_traits
#> category group
#> 1 Species group Functional group
#> 2 Species group Functional group
#> 3 Species group Functional group
#> 4 Species group Functional group
#> 5 Species group Functional group
#> 6 Species group Functional group
#> 7 Species group Functional group
#> 8 Species group Functional group
#> 9 Species group Functional group
#> 10 Species importance to society CITES Annex
#> 11 Species importance to society CITES Annex
#> 12 Species importance to society CITES Annex
#> 13 Species importance to society Habitats Directive Annex
#> 14 Species importance to society Habitats Directive Annex
#> 15 Species importance to society IUCN Red List Category
#> 16 Species importance to society IUCN Red List Category
#> 17 Species importance to society IUCN Red List Category
#> 18 Species importance to society MSFD indicators
#> 19 Species importance to society MSFD indicators
#> 20 Species importance to society MSFD indicators
#> 21 Species importance to society MSFD indicators
#> 22 Species importance to society MSFD indicators
#> 23 Species importance to society MSFD indicators
#> 24 Species importance to society MSFD indicators
#> 25 Species importance to society MSFD indicators
#> 26 Species importance to society MSFD indicators
#> 27 Species importance to society MSFD indicators
#> 28 Species importance to society MSFD indicators
#> 29 Species importance to society MSFD indicators
#> 30 Species importance to society MSFD indicators
#> 31 Species importance to society MSFD indicators
#> 32 Species importance to society MSFD indicators
#> selection
#> 1 algae
#> 2 angiosperms
#> 3 benthos
#> 4 birds
#> 5 mammals
#> 6 phytoplankton
#> 7 pisces
#> 8 reptiles
#> 9 zooplankton
#> 10 I
#> 11 II
#> 12 III
#> 13 II
#> 14 IV
#> 15 data deficient
#> 16 least concern
#> 17 near threatened
#> 18 Black Sea proposed indicators
#> 19 HELCOM core biodiversity indicators
#> 20 Mediterranean proposed indicators - Adriatic Sea
#> 21 Mediterranean proposed indicators - Aegean-Levantine Sea
#> 22 Mediterranean proposed indicators - Ionian Sea
#> 23 Mediterranean proposed indicators - Mediterranean Sea
#> 24 Mediterranean proposed indicators - Western Mediterranean
#> 25 OSPAR candidate indicators: Bay of Biscay and the Iberian Coast
#> 26 OSPAR candidate indicators: Celtic Seas
#> 27 OSPAR candidate indicators: Greater North Sea including outside EU
#> 28 OSPAR candidate indicators: North Sea
#> 29 OSPAR common indicators: Bay of Biscay and Iberian Coast
#> 30 OSPAR common indicators: Celtic Seas
#> 31 OSPAR common indicators: Greater North Sea
#> 32 OSPAR common indicators: Greater North Sea including outside EU
#> selectid
#> 1 Algae
#> 2 Angiosperms
#> 3 Benthos
#> 4 Birds
#> 5 Mammals
#> 6 phytoplankton
#> 7 pisces
#> 8 Reptiles
#> 9 zooplankton
#> 10 28_280_0
#> 11 28_281_0
#> 12 28_282_0
#> 13 26_269_0
#> 14 26_271_0
#> 15 1_8_3
#> 16 1_7_3
#> 17 1_6_3
#> 18 23_285_41
#> 19 23_285_29
#> 20 23_285_31
#> 21 23_285_32
#> 22 23_285_33
#> 23 23_285_34
#> 24 23_285_30
#> 25 23_285_35
#> 26 23_285_36
#> 27 23_285_37
#> 28 23_285_38
#> 29 23_285_44
#> 30 23_285_45
#> 31 23_285_46
#> 32 23_285_40
```

## Query by location
Expand Down Expand Up @@ -206,21 +283,21 @@ www.emodnet-biology.eu/toolbox, consulted on yyyy-mm-dd.
Regarding the citation of the individual datasets, the following
guidelines should be taken into account:

- If any individual data source of EurOBIS constitutes a significant
- If any individual data source of EurOBIS constitutes a significant
proportion of the downloaded and used records (e.g. more than 10% of
the data is derived from a single source), the individual data
source should also be cited.
- If any individual data source of EurOBIS constitutes a substantial
- If any individual data source of EurOBIS constitutes a substantial
proportion of the downloaded and used records (e.g. more than 25% of
the data is derived from a single source or the data is essential to
arrive at the conclusion of the analysis), the manager or custodian
of this data set should be contacted.
- In any case, it may be useful to contact the data custodian
- In any case, it may be useful to contact the data custodian
directly. The data custodian might have additional data available
that may strengthen the analysis or he/she might be able to provide
additional helpful information that may not be apparent from the
provided metadata.
- The data may not be redistributed without the permission of the
- The data may not be redistributed without the permission of the
appropriate data owners. If data are extracted from the EMODnet Data
Portal for redistribution, please contact us at <[email protected]>.

Expand Down
2 changes: 1 addition & 1 deletion man/eurobis_list_datasets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/eurobis_list_regions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3d4690

Please sign in to comment.