Author: Brian Maitner
Date: 2024-10-14

# NSR R package

#### Brian Maitner

#### 2024-10-14

## Native Species Resolver

The package `NSR` is designed to interact with the Native Species Resolver of the Botanical Information and Ecology Network.

#Installing NSR

    library(devtools)
    install_github("EnquistLab/RNSR/NSR")

#The easiest case: one species in one political division

    library(NSR)
    NSR_simple(species = "Acer rubrum",
               country =  "Canada",
               state_province = "Ontario")

    ##        family genus     species country state_province county_parish
    ## 1 Sapindaceae  Acer Acer rubrum  Canada        Ontario
    ##      poldiv_full    poldiv_type native_status_country
    ## 1 Canada:Ontario state_province                     N
    ##   native_status_state_province native_status_county_parish native_status
    ## 1                            N                                         N
    ##                 native_status_reason native_status_sources isIntroduced
    ## 1 Native to region, as per checklist            powo, usda            0
    ##   isCultivatedNSR is_cultivated_taxon user_id
    ## 1               0                   0       1

#Multiple species When submitting data into the NSR, the function expects a data.frame containing 5 columns as input, however only the columns “species” and “country” (the first two) need to be populated. If you ever forget the input format, you can use the function NSR_template as a quick look-up, or to populate.

    head(NSR_template())

    ##   species country state_province county_parish user_id
    ## 1      NA      NA             NA            NA      NA

#Example data

    #First, pull the example data that are included with the package
    data("nsr_testfile")
    head(nsr_testfile)

    ##                   taxon   country    state_province county_parish user_id
    ## 1            Eucalyptus Australia Western Australia                     1
    ## 2 Abrothallus bertianus   Austria                                       2
    ## 3        Cocos nucifera   Jamaica                                       3
    ## 4            Eucalyptus    Mexico                                       4
    ## 5     Larrea tridentata    Mexico                                       5
    ## 6      Pinus ayacahuite    Mexico                                       6

    example_results <- NSR(nsr_testfile)

    head(example_results)

    ##           family       genus               species   country    state_province
    ## 1      Myrtaceae  Eucalyptus                       Australia Western Australia
    ## 2                Abrothallus Abrothallus bertianus   Austria
    ## 3      Arecaceae       Cocos        Cocos nucifera   Jamaica
    ## 4      Myrtaceae  Eucalyptus                          Mexico
    ## 5 Zygophyllaceae      Larrea     Larrea tridentata    Mexico
    ## 6       Pinaceae       Pinus      Pinus ayacahuite    Mexico
    ##   county_parish                 poldiv_full    poldiv_type
    ## 1               Australia:Western Australia state_province
    ## 2                                   Austria        country
    ## 3                                   Jamaica        country
    ## 4                                    Mexico        country
    ## 5                                    Mexico        country
    ## 6                                    Mexico        country
    ##   native_status_country native_status_state_province
    ## 1                     N                            N
    ## 2                     A
    ## 3                     I
    ## 4                     I
    ## 5                     N
    ## 6                     N
    ##   native_status_county_parish native_status
    ## 1                                         N
    ## 2                                         A
    ## 3                                         I
    ## 4                                         I
    ## 5                                         N
    ## 6                                         N
    ##                     native_status_reason native_status_sources isIntroduced
    ## 1     Native to region, as per checklist                  powo            0
    ## 2  Absent from all checklists for region                  powo            1
    ## 3 Introduced to region, as per checklist    fwi, powo, weakley            1
    ## 4 Introduced to region, as per checklist                  powo            1
    ## 5     Native to region, as per checklist          mexico, powo            0
    ## 6     Native to region, as per checklist          mexico, powo            0
    ##   isCultivatedNSR is_cultivated_taxon user_id
    ## 1               0                   0       1
    ## 2               0                   0       2
    ## 3               0                   0       3
    ## 4               0                   0       4
    ## 5               0                   0       5
    ## 6               0                   0       6

#Source metadata To access metadata for the sources currently consulted by the NSR, use the function `NSR_metadata()`. To figure out which political divisions contain checklists that were consulted by the NSR, use the function `NSR_political_divisions()`.

    sources <- NSR_metadata()

    checklist_per_political_divisions <- NSR_political_divisions()

    # If you'd rather see which political divisions are available within each checklist, set "by_country" to FALSE

    political_divisions_per_checklist <- NSR_political_divisions(by_country = FALSE)