knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE, fig.show = "hold", fig.width = 7, fig.height = 5 )
library("pestr") library("dplyr")
Assume that you are assessing pest threats to Abies alba -- European silver fir. It would be wise to go to EPPO Global Database, type Abies alba in search field and check all the information you need, copy paste them into spreadsheet and make some analyses. On the other hand, you can just use pestr
package and do everything easily from R
directly saving time on whole copy-pasting procedures. To make this example easy lets assume that your goal is to check number of taxons and number of particular types (major, minor, etc.) of pests. Therefore steps you would need to make in R
are presented below.
First you need valid eppocode of Abies alba. To do this you will need to use eppo_names_tables
function and save your results to a variable like in the code example below:
abies_alba <- eppo_names_tables("Abies alba")
This variable will be our input for next step.
We can now look for all the existing pests of Abies alba that exists in EPPO Data Services. To do this we need to use eppo_tabeltools_pests
function. There are two options how you can access the information.
eppo_names_tables
output as an argument:You will need result of eppo_names_tables
function as first argument and the second one is token -- which allows you to connect to EPPO API. You get it by registering to EPPO Data Services which is free of charge. You need to paste your token to create_eppo_token
function and assign the results to a variable (here we use eppo_token
) that will be used among all pestr
functions that connect to EPPO API.
eppo_tabletools_pests
will take 3 arguments with this approach:
create_eppo_token
;TRUE
Below code shows this in action:
### Firsr create eppo_token variable eppo_token <- eppo_create_token("<place your eppo token here>") ### For token argument, please use eppo_token abies_alba_pests <- eppo_tabletools_pests(token = eppo_token, raw_eppocodes = "ABIAL", use_raw_codes = TRUE)
abies_alba_pests <- readRDS("vignette_mock_pests.RDS")
Looking at structure of abies_alba_pests
variable we see that it is a list containing 2 data.frame
.
str(abies_alba_pests)
The long_table element contains what we actually need for our analyses: pest_eppocode and labelclass columns. Lets start with latter.
Pest types are stored in labelclass column. We will use few very basic R
and dplyr
package commands to check numbers we are interested in.
### First select colums labelclass from long_table element, ### and use table to check frequencies abies_alba_pests$long_table %>% dplyr::select(labelclass) %>% table() ### Than we can create very simple barplot to visualize number of ### species in particular type of pest abies_alba_pests$long_table %>% dplyr::select(labelclass) %>% table() %>% barplot(xlab = "Type of pest", ylab = "Number of species", col = "#AF0011", ylim = c(0, 30))
Obtaining number of pests taxons is not very complicated. Since we can use eppocodes
directly, we can pass whole column to eppo_tabletools_taxo
function, which will retrieve data on pests taxonomy.
### Extract eppocodes of pests pests_eppocodes <- abies_alba_pests$long_table %>% dplyr::select(pests_eppocode) %>% unlist()
Now, we can pass pest_eppocodes
variable as raw_eppocodes
argument:
pests_taxonomy <- eppo_tabletools_taxo(token = eppo_token, raw_eppocodes = pests_eppocodes, use_raw_codes = TRUE)
pests_taxonomy <- readRDS("vignette_mock_pests_taxo.RDS")
This time we can take a shortcut and use second element of list compact_table
. We can now check the numbers using table
function and plot results with simple barplot
.
pests_taxonomy$compact_table %>% dplyr::select(taxonomy) %>% table() pests_taxonomy$compact_table %>% dplyr::select(taxonomy) %>% table() %>% barplot(xlab = "Classification of pest", ylab = "Number of species", col = "#AF0011", ylim = c(0, 30))
Now, knowing basics of how functions interacts, you are ready to play with your own workflows and analyses.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.