From 35876f159f7abe68330d8c6576f8fe258a43fb98 Mon Sep 17 00:00:00 2001
From: Francesco Sabatini <francesco.sabatini@idiv.de>
Date: Wed, 2 Dec 2020 10:55:12 +0100
Subject: [PATCH] Updated to exclude  plots

---
 code/04_buildHeader.Rmd   |  3 ++-
 code/06_buildDT.Rmd       | 14 ++++++++++----
 code/07_buildCWMs.Rmd     |  8 ++++++++
 code/08_Documentation.Rmd |  2 +-
 4 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/code/04_buildHeader.Rmd b/code/04_buildHeader.Rmd
index ad7b3f8..677793a 100644
--- a/code/04_buildHeader.Rmd
+++ b/code/04_buildHeader.Rmd
@@ -152,7 +152,8 @@ Pfe-o-05- 1707854
 ```{r, eval=T}
 header0 <- header0 %>% 
   filter(!PlotObservationID %in% c(1707776, 1707779:1707782, 1707849, 1707854)) %>% 
-  filter(Dataset != "$Coastal_Borja")
+  filter(Dataset != "$Coastal_Borja") %>% 
+  filter(Dataset != "$Coastal_Poland") 
 ```
 
 
diff --git a/code/06_buildDT.Rmd b/code/06_buildDT.Rmd
index 1979e32..98fdec7 100644
--- a/code/06_buildDT.Rmd
+++ b/code/06_buildDT.Rmd
@@ -63,19 +63,25 @@ DT0 <- readr::read_delim("../sPlot_data_export/sPlot_3_0_2_species_test.csv",
                                 x_ = col_double()
                               )
                          ) 
-nplots <- length(unique(DT0$PlotObservationID))
-nspecies <- length(unique(DT0$`Matched concept`))
+
 ```
 Match plots with those in `header`
 ```{r}
 load("../_output/header_sPlot3.0.RData")
 DT0 <- DT0 %>% 
   filter(PlotObservationID %in% unique(header$PlotObservationID))
+
+nplots <- length(unique(DT0$PlotObservationID))
+nspecies <- length(unique(DT0$`Matched concept`))
+# Plots in header but not in DT
+empty.plots <- header %>% 
+  filter(!PlotObservationID %in% unique(DT2$PlotObservationID)) %>% 
+  pull(PlotObservationID)
 ```
 
 
-The DT table includes `r nrow(DT0)` species * plot records, across `r nplots` plots. Before taxonomic resolution, there are `r nspecies` species .  
-\newline
+The DT table includes `r nrow(DT0)` species * plot records, across `r nplots` plots. Before taxonomic resolution, there are `r nspecies` species. There are `r length(empty.plots)`. These are plots where the only species reported in Turboveg 3 are not identified (and not in the taxonomic list). Should these be deleted from `header`?
+<br>
 
 
 ```{r, echo=F}
diff --git a/code/07_buildCWMs.Rmd b/code/07_buildCWMs.Rmd
index 99c0eb6..65064c3 100644
--- a/code/07_buildCWMs.Rmd
+++ b/code/07_buildCWMs.Rmd
@@ -412,6 +412,14 @@ CWM <- CWM1 %>%
   arrange(PlotObservationID)
 
 ```
+
+```{r, echo=F}
+# align to header (to avoid recalculating cached CWMs)
+CWM <- CWM %>% 
+  filter(PlotObservationID %in% header$PlotObservationID)
+```
+
+
 ### 2.1 Explore CWM output
 ```{r, echo=F}
 knitr::kable(CWM %>% 
diff --git a/code/08_Documentation.Rmd b/code/08_Documentation.Rmd
index fe090dc..4fec4e5 100644
--- a/code/08_Documentation.Rmd
+++ b/code/08_Documentation.Rmd
@@ -265,7 +265,7 @@ knitr::kable(CWM %>%
                   latex_options = "basic", 
                   full_width = F, position = "center")
 ```
-The CWM table contains `r nrow(CWM)` entries, i.e., the combination between `r CWM %>% distinct(PlotObservationID) %>% nrow()` unique plots, and `r CWM %>% distinct(variable) %>% nrow()`. 
+The CWM table contains `r nrow(CWM)` entries, i.e., the combination between `r CWM %>% distinct(PlotObservationID) %>% nrow()` unique plots, and `r CWM %>% distinct(variable) %>% nrow()` traits. 
 
 
 
-- 
GitLab