mermaidr is an R package that enables you to access data from MERMAID, an open-source data platform developed to help you collect, analyze, and share coral reef monitoring data. Through mermaidr you can access data from MERMAID directly in R.

For more information and detailed instructions on usage, please visit the package website.

If you are new to the R programming language, our new R users guide is a great place to start! If you find yourself stuck, please don’t hesitate to ask for help.

Installation

You can install mermaidr from GitHub with:

# install.packages("remotes")
remotes::install_github("data-mermaid/mermaidr")

Usage

Through mermaidr, you can access aggregated data from your coral reef surveys. To do this, first load the package and access your MERMAID projects:

At this point, you will have to authenticate to the Collect app. R will help you do this automatically by opening a browser window for you to log in to Collect, either via Google sign-in or username and password - however you normally do! Once you’ve logged in, come back to R. Your login credentials will be stored for a day, until they expire, and you will need to log in again. The package handles the expiration for you, so just log in again when prompted.

This function gives us information on your projects, including project countries, the number of sites, tags, data policies, and more:

projects
#> # A tibble: 16 × 21
#>    id    name  countries num_sites num_active_sample_un…¹ num_sample_units tags 
#>    <chr> <chr> <chr>         <int>                  <int>            <dbl> <chr>
#>  1 e1ef… 2016… Fiji              9                     10               80 WCS …
#>  2 170e… 2018… Fiji             10                      5              121 WCS …
#>  3 d065… 2019… Fiji             31                      3               32 WCS …
#>  4 1fbd… a2    Canada; …         9                      9                0 WWF-…
#>  5 3a9e… Aceh… Indonesia        18                     54              199 WCS …
#>  6 bacd… Beli… Belize; …        39                    136              260 WCS …
#>  7 a1b7… Grea… Fiji             76                      8              648 Fiji…
#>  8 507d… Kari… Indonesia        43                     18              842 WCS …
#>  9 75ef… Kubu… Fiji             78                      1             1145 WCS …
#> 10 5679… Mada… Madagasc…        33                      0               49 WCS …
#> 11 4080… Mada… Madagasc…        74                      4               84 WCS …
#> 12 4d79… MERM… Indonesi…        13                     73               31 test…
#> 13 2c0c… Shar… Canada; …        28                     61                7 <NA> 
#> 14 02e6… TWP … Indonesia        14                     10                2 WCS …
#> 15 2d6c… WCS … Mozambiq…        74                      6              247 WCS …
#> 16 9de8… XPDC… Indonesia        37                     71              450 <NA> 
#> # ℹ abbreviated name: ¹​num_active_sample_units
#> # ℹ 14 more variables: suggested_citation <chr>, bbox <df[,4]>, notes <chr>,
#> #   status <chr>, data_policy_beltfish <chr>, data_policy_benthiclit <chr>,
#> #   data_policy_benthicpit <chr>, data_policy_habitatcomplexity <chr>,
#> #   data_policy_bleachingqc <chr>, data_policy_benthicpqt <chr>,
#> #   data_policy_macroinvertebrate <chr>, includes_gfcr <lgl>, created_on <chr>,
#> #   updated_on <chr>

To focus on just one or a few projects, you can filter by fields like the project name, country, or tags using the dplyr package. For example, I’ll narrow in on the WCS Mozambique Coral Reef Monitoring project.

library(dplyr)

wcs_mozambique <- projects %>%
  filter(name == "WCS Mozambique Coral Reef Monitoring")

You can access data collected on fishbelt, benthic LIT, benthic PIT, macroinvertebrates, bleaching, or habitat complexity - the main function to pull data related to your project is mermaid_get_project_data():

wcs_mozambique_fishbelt_samples <- wcs_mozambique %>%
  mermaid_get_project_data(method = "fishbelt", data = "sampleevents")

The data = "sampleevents" argument specifies that I’d like to pull data summarised to the level of a sample event, which is a site and date - we can see that this pulls information about the site and date of samples, along with aggregations like the total biomass of that site/date, and broken down by trophic group and fish family.

wcs_mozambique_fishbelt_samples
#> # A tibble: 79 × 94
#>    id           project project_admins country contact_link tags  site  latitude
#>    <chr>        <chr>   <chr>          <chr>   <chr>        <chr> <chr>    <dbl>
#>  1 36316e77-ea… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Bunt…    -12.6
#>  2 cc6b0a95-64… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Chec…    -26.8
#>  3 83353357-69… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Mate…    -12.2
#>  4 364e439d-e4… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Jagg…    -26.8
#>  5 324f2b0a-4a… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Ligh…    -12.3
#>  6 1c2d7c1e-c6… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Kisi…    -11.0
#>  7 cff14283-95… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Kisi…    -11.0
#>  8 de6b403d-29… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Kisi…    -11.0
#>  9 fcff6a0b-4c… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Two …    -21.8
#> 10 910b3d5b-fa… WCS Mo… Emily Darling… Mozamb… https://dat… WCS … Luta…    -12.3
#> # ℹ 69 more rows
#> # ℹ 86 more variables: longitude <dbl>, reef_exposure <chr>, reef_type <chr>,
#> #   reef_zone <chr>, tide <lgl>, visibility <lgl>, current <lgl>,
#> #   depth_avg <dbl>, depth_sd <dbl>, management <chr>,
#> #   management_secondary <lgl>, management_est_year <dbl>,
#> #   management_size <dbl>, management_parties <chr>,
#> #   management_compliance <chr>, management_rules <chr>, sample_date <date>, …

If you’d like data related to the units of survey (for example, to transects or quadrats), it’s just a matter of changing data to “sampleunits”:

wcs_mozambique %>%
  mermaid_get_project_data(method = "fishbelt", data = "sampleunits")
#> # A tibble: 108 × 73
#>    project    project_admins country contact_link tags  site  latitude longitude
#>    <chr>      <chr>          <chr>   <chr>        <chr> <chr>    <dbl>     <dbl>
#>  1 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Kisi…    -11.0      40.7
#>  2 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Ligh…    -12.3      40.6
#>  3 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Aqua…    -21.8      35.5
#>  4 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Pang…    -11.0      40.6
#>  5 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Pemb…    -13.0      40.6
#>  6 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Aqua…    -21.8      35.5
#>  7 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Pemb…    -13.0      40.6
#>  8 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Jagg…    -26.8      32.9
#>  9 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Papa…    -11.0      40.7
#> 10 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Lond…    -12.9      40.5
#> # ℹ 98 more rows
#> # ℹ 65 more variables: reef_exposure <chr>, reef_slope <lgl>, reef_type <chr>,
#> #   reef_zone <chr>, sample_time <time>, tide <lgl>, visibility <lgl>,
#> #   current <lgl>, depth <dbl>, relative_depth <lgl>, management <chr>,
#> #   management_secondary <lgl>, management_est_year <dbl>,
#> #   management_size <dbl>, management_parties <chr>,
#> #   management_compliance <chr>, management_rules <chr>, sample_date <date>, …

And raw observations are available by changing it to “observations”:

wcs_mozambique %>%
  mermaid_get_project_data(method = "fishbelt", data = "observations")
#> # A tibble: 2,637 × 55
#>    project    project_admins country contact_link tags  site  latitude longitude
#>    <chr>      <chr>          <chr>   <chr>        <chr> <chr>    <dbl>     <dbl>
#>  1 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  2 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  3 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  4 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  5 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  6 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  7 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  8 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#>  9 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#> 10 WCS Mozam… Emily Darling… Mozamb… https://dat… WCS … Moti…    -14.4      40.7
#> # ℹ 2,627 more rows
#> # ℹ 47 more variables: reef_exposure <chr>, reef_slope <lgl>, reef_type <chr>,
#> #   reef_zone <chr>, sample_time <time>, tide <lgl>, visibility <lgl>,
#> #   current <lgl>, depth <dbl>, relative_depth <lgl>, management <chr>,
#> #   management_secondary <lgl>, management_est_year <dbl>,
#> #   management_size <dbl>, management_parties <chr>,
#> #   management_compliance <chr>, management_rules <chr>, sample_date <date>, …

For more details on accessing project data, please see the Accessing Project Data article.

You may also want to access data that is not related to projects. To access this data, you do not need to authenticate R with MERMAID.

For example, you can pull reference data (the names and information of the fish and benthic attributes you can choose in MERMAID), using mermaid_get_reference():

mermaid_get_reference(reference = "fishfamilies")
#> # A tibble: 161 × 8
#>    id     name  biomass_constant_a biomass_constant_b biomass_constant_c regions
#>    <chr>  <chr>              <dbl>              <dbl>              <dbl> <chr>  
#>  1 3f7bf… Acan…            0.0256                2.97              0.990 Centra…
#>  2 455a7… Achi…            0.0164                3.11              1     Tropic…
#>  3 78d71… Acip…            0.00497               3.25              1     Tropic…
#>  4 0d990… Albu…            0.0105                2.99              1     Tropic…
#>  5 530c6… Amba…            0.0130                2.96              1     Centra…
#>  6 e8dfe… Angu…            0.0006                3.35              1     Tropic…
#>  7 cf2b1… Anom…            0.0112                3.04              1     Tropic…
#>  8 9ef4d… Ante…            0.0200                3.01              1     Centra…
#>  9 7a931… Aplo…            0.00487               3.16              1     Centra…
#> 10 26fff… Apog…            0.0142                3.15              0.993 Centra…
#> # ℹ 151 more rows
#> # ℹ 2 more variables: created_on <chr>, updated_on <chr>

Using this function, you can access the fish family, fish genera, fish species, and benthic attributes references by changing the reference argument.

You can also get a list of all projects (not just your own):

mermaid_get_projects()
#> # A tibble: 113 × 21
#>    id    name  countries num_sites num_active_sample_un…¹ num_sample_units tags 
#>    <chr> <chr> <chr>         <int>                  <int>            <dbl> <chr>
#>  1 13a2… 0909… <NA>              0                      0                0 <NA> 
#>  2 f9c5… 1313… <NA>              0                      1                0 <NA> 
#>  3 60dd… 2013… Fiji             17                      8              130 WCS …
#>  4 7376… 2014… Fiji             24                      2              345 WCS …
#>  5 ac93… 2016… Fiji             24                      2              146 WCS …
#>  6 e1ef… 2016… Fiji              9                     10               80 WCS …
#>  7 d549… 2017… Fiji             31                      0              279 WCS …
#>  8 c0ba… 2018… Fiji             22                      0              130 WCS …
#>  9 170e… 2018… Fiji             10                      5              121 WCS …
#> 10 95e0… 2019… Fiji             44                      0              406 WCS …
#> # ℹ 103 more rows
#> # ℹ abbreviated name: ¹​num_active_sample_units
#> # ℹ 14 more variables: suggested_citation <chr>, bbox <df[,4]>, notes <chr>,
#> #   status <chr>, data_policy_beltfish <chr>, data_policy_benthiclit <chr>,
#> #   data_policy_benthicpit <chr>, data_policy_habitatcomplexity <chr>,
#> #   data_policy_bleachingqc <chr>, data_policy_benthicpqt <chr>,
#> #   data_policy_macroinvertebrate <chr>, includes_gfcr <lgl>, …

As well as all sites:

mermaid_get_sites()
#> # A tibble: 2,156 × 12
#>    id         name  latitude longitude notes project country reef_type reef_zone
#>    <chr>      <chr>    <dbl>     <dbl> <chr> <chr>   <chr>   <chr>     <chr>    
#>  1 0415d9e5-… mysi…     -1        -1   <NA>  2c56b9… Bangla… atoll     back reef
#>  2 547dae1b-… bulk…     47.5     -81.8 <NA>  2c0c98… Canada  atoll     back reef
#>  3 874c5a80-… dupe…      1         1   <NA>  c08ff9… Canada  atoll     back reef
#>  4 42d67bb1-… dupe…      1         1   <NA>  c08ff9… Canada  atoll     back reef
#>  5 afe4dac0-… meli…     49      -110   <NA>  ea4751… Canada  atoll     back reef
#>  6 6cd334f9-… meli…     49      -110   <NA>  ea4751… Canada  atoll     back reef
#>  7 af55820b-… BA02     -17.4     178.  Sour… 89f2d4… Fiji    atoll     back reef
#>  8 9c2f0080-… BA02     -17.4     178.  Sour… a1b7ff… Fiji    atoll     back reef
#>  9 03e5576e-… BA03     -17.4     178.  <NA>  89f2d4… Fiji    atoll     back reef
#> 10 a9c8b3e0-… BA03     -17.4     178.  <NA>  eae004… Fiji    atoll     back reef
#> # ℹ 2,146 more rows
#> # ℹ 3 more variables: exposure <chr>, created_on <chr>, updated_on <chr>

And all managements:

mermaid_get_managements()
#> # A tibble: 1,886 × 18
#>    id         name   size name_secondary est_year notes no_take periodic_closure
#>    <chr>      <chr> <dbl> <chr>             <int> <chr> <lgl>   <lgl>           
#>  1 a10d4cfc-… 123     123 <NA>               1979 <NA>  FALSE   TRUE            
#>  2 0e9aa677-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  3 248e26fe-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  4 9f54940e-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  5 9788b7f9-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  6 d70de8ff-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  7 9c204b0d-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  8 3ad9eb1e-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#>  9 9168b477-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#> 10 9b1df02a-… 678j…     7 <NA>                 NA <NA>  TRUE    FALSE           
#> # ℹ 1,876 more rows
#> # ℹ 10 more variables: open_access <lgl>, size_limits <lgl>,
#> #   gear_restriction <lgl>, species_restriction <lgl>,
#> #   access_restriction <lgl>, compliance <chr>, parties <chr>, rules <chr>,
#> #   created_on <chr>, updated_on <chr>

There is additional data available from the MERMAID API, both related to specific projects and not. If you think you’ll need to use these, please see mermaid_get_endpoint() and mermaid_get_project_endpoint().

This is a small sample of the wealth of data that’s available on your MERMAID projects, and on the ecosystem as a whole! Please explore the package website for more.