Combine_AIM_LMF: Combine_AIM_LMF

Description Usage Arguments Author(s) Examples

View source: R/Combine_AIM_LMF.R

Description

Puts TerrADat (Assessment, Inventory, and Monitoring dataset) and LMF (Landscape Monitoring Framework dataset) in the same format, adds R or F prefix to EcologicalSiteId for LMF based on the official ecological site list from EDIT, and merges the two datasets into one. Returns dataframe.

Usage

1
Combine_AIM_LMF(TerrADat_Path, EDIT_List_Path, Internal)

Arguments

TerrADat_Path

file path to the TerrADat geodatabase. Set to NULL if you are internal (within Bureau of Land Management network/vpn)

EDIT_List_Path

file path to the .csv with list of formal ecological site ids (on the sharepoint with Site Summary Tool template)

Internal

logical. TRUE if within BLM network/on vpn. FALSE if accessing TerrADat via external geodatabase.

Author(s)

Rachel Burke, ecologist/analyst @ Jornada

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# If external:
TDat_LMF <- Combine_AIM_LMF(TerrADat_Path = "~/gdbs/TerrADat.gdb",
                   EDIT_List_Path = "~/Projects/ESSTool/Defaults",
                   Internal = FALSE)
# If internal:
TDat_LMF <- Combine_AIM_LMF(TerrADat_Path = NULL,
                   EDIT_List_Path = "~/Projects/ESSTool/Defaults",
                   Internal = TRUE)

## The function is currently defined as
function (TerrADat_Path, EDIT_List_Path, Internal)
{
    if (!Internal) {
        TerrADat <- sf::st_read(dsn = TerrADat_Path, layer = "TerrADat")
        LMF <- sf::st_read(dsn = TerrADat_Path, layer = "LMF")
        TerrADat <- as.data.frame(TerrADat)
        TerrADat <- dplyr::select(TerrADat, -Shape)
        LMF <- as.data.frame(LMF)
        LMF <- dplyr::select(LMF, -Shape)
    }
    if (Internal) {
        TerrADat <- TerrADat
        LMF <- LMF
    }
    EDIT <- read.csv(file = paste0(EDIT_List_Path, "/", "EDIT_public_ecological_site_list.csv"))
    EDIT[["EcoSiteId_Stripped"]] <- gsub(EDIT[["new_es_symbol"]],
        pattern = "^[RF]", replacement = "")
    ecosite_lut <- unique(EDIT[, c("new_es_symbol", "EcoSiteId_Stripped")])
    any(table(ecosite_lut[["EcoSiteId_Stripped"]]) > 1)
    trouble_ids <- names(table(ecosite_lut[["EcoSiteId_Stripped"]]))[table(ecosite_lut[["EcoSiteId_Stripped"]]) >
        1]
    ecosite_lut_drop_bad <- dplyr::filter(ecosite_lut, !EcoSiteId_Stripped ==
        trouble_ids)
    EcoSites_Update <- dplyr::mutate(ecosite_lut_drop_bad, EcologicalSiteId = EcoSiteId_Stripped)
    LMF_EcoSite <- merge(LMF, EcoSites_Update, by = "EcologicalSiteId")
    LMF_EcoSite <- dplyr::select(LMF_EcoSite, -EcologicalSiteId)
    LMF_EcoSite <- dplyr::rename(LMF_EcoSite, EcologicalSiteId = new_es_symbol)
    LMF_EcoSite <- dplyr::select(LMF_EcoSite, -EcoSiteId_Stripped)
    TerrADat[setdiff(names(LMF_EcoSite), names(TerrADat))] <- NA
    LMF_EcoSite[setdiff(names(TerrADat), names(LMF_EcoSite))] <- NA
    TerrADat[setdiff(names(LMF_EcoSite), names(TerrADat))] <- NA
    LMF_EcoSite[setdiff(names(TerrADat), names(LMF_EcoSite))] <- NA
    TDat_LMF <- rbind(TerrADat, LMF_EcoSite)
    TDat_LMF$DateVisited <- sub("^(\d{4}).*$", "\1", TDat_LMF$DateVisited)
    TDat_LMF <- TDat_LMF %>% dplyr::rename(Year = DateVisited)
    EDIT_rename <- EDIT %>% rename(EcologicalSiteId = new_es_symbol)
    output <- merge(TDat_LMF, EDIT_rename, by = "EcologicalSiteId",
        all = TRUE)
    output <- output %>% dplyr::select(-EcoSiteId_Stripped)
    return(output)
  }

R-Burke/SiteSummaryTool documentation built on Oct. 15, 2020, 8:21 p.m.