-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfri - psp field form v3.qmd
199 lines (162 loc) · 4.66 KB
/
fri - psp field form v3.qmd
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
---
title: " "
format:
pdf:
documentclass: article
classoption: landscape
papersize: "a4"
fontsize: "8pt"
mainfont: Arial
# monofont: Fira Code
geometry:
#- showframe
- top=10mm
- bottom=10mm
- left=10mm
- right=10mm
- heightrounded
# margin-left: "1cm"
# margin-right: "1cm"
# margin-top: "1cm"
# margin-bottom: "1cm"
include-in-header:
text:
\usepackage{makecell}
editor: source
keep-tex: true
---
```{r, include=FALSE}
## Calculated variables
library(dplyr)
library(kableExtra)
# https://stackoverflow.com/questions/44486493/produce-a-table-spanning-multiple-pages-using-kable
plot_code <- "OOMSI01"
plot_location <- "OOMSIS"
dat <- tibble(read.csv("dat1.csv"))
# dat <- tibble(
# quadrat = "02",
# tree_no = 1:40,
# tree_species = LETTERS[1:40],
# sf = c("?", rep("", 37), "?", ""),
# tree_condition = rep(LETTERS[11:20], 4),
# coord_east = sample(100:200, 40, replace = F),
# coord_north = sample(200:300, 40, replace = F),
# tree_dbh_pom = 1.3,
# tree_dbh_previous = sample(15:100, 40, replace = T)
# )
dat <- dat |>
mutate(across(everything(), as.character))
# add 10 empty rows
for (j in 1:10) dat <- add_row(dat,.after = nrow(dat))
dat[(nrow(dat)-10):nrow(dat),] <- ""
dat$quadrat <- dat$quadrat[[1]]
col_empty <- c(
"tree_dbh_current", "DBH_DF", "tree_status", "stem_form", "crown_position", "crown_form", "crown_d1",
"crown_d2","height_distance", "height_pom","height_merH","height_CrB","height_TotH"
)
col_names <- c(
"Qua-\ndrat", "Tree\nNo.", "Species\nCode", "SF", "Tree\nCond.", "East\n(m)", "North\n(m)", "POM\n(m)",
"Previous\n(cm)", "Current\n(cm)", "DF", "Tree\nStatus", "Stem\nForm","Posi\ntion","Form","d1","d2","Dist\n(m)",
"POM","Mer H","Cr B","Tot H"
)
full_table <- list()
# max 30 rows per page, otherwise split data into 2 tables. Max Tree Number in data now is 47.
if (nrow(dat) > 30) {
nPages <- 2
full_table[[1]] <- dat[1:30,]
full_table[[2]] <- dat[31:nrow(dat),]
full_table[[1]][, col_empty] <- ""
full_table[[2]][, col_empty] <- ""
} else {
nPages <- 1
full_table[[1]] <- dat
full_table[[1]][, col_empty] <- ""
}
## add column number as first row
full_table3 <- list()
for (i in 1:nPages){
full_table3[[i]] <- setNames(paste0("(", 1:22, ")"), names(full_table[[i]])) |>
bind_rows(full_table[[i]])
}
```
<!-- TITLE COLUMN -->
:::::::: {layout="[0.2, 0.6, 0.2]"}
::: {.column width="20%"}
Form: **PSP/PNGFRI**
:::
:::: {.column width="60%"}
::: {.center data-latex=""}
**PLOT REASSESSMENT AND TREE DESCRIPTION**
:::
::::
:::: {.column width="20%"}
::: {.flushright data-latex=""}
Page \_\_\_ of \_\_\_
:::
::::
::::::::
::::: {layout="[1]"}
:::: {.column width="100%"}
::: {.center data-latex=""}
**Open Foris Arena, FAO**
:::
::::
:::::
<!-- First line -->
::::::::: {layout="[0.2, 0.2, 0.2, 0.2, 0.2]"}
::: {.column width="20%"}
PSP ID: **`{r} plot_code`**
:::
::: {.column width="20%"}
Location: **`{r} plot_location`**
:::
::: {.column width="15%"}
:::
::: {.column width="25%"}
Assessed by: .......................
:::
:::: {.column width="20%"}
::: {.flushright data-latex=""}
Date: ..... / ..... / .......
:::
::::
:::::::::
<!-- TABLE -->
```{r, echo=F }
kbl_field_form <- list()
for (i in 1:nPages) {
## Style 1srt row same as headers
vec_row1 <- c(T, rep(F, nrow(full_table3[[i]]) - 1))
kbl_field_form[[i]] <- full_table3[[i]] |>
kbl(
col.names = linebreak(col_names),
escape = F,
booktabs = F,
# longtable = TRUE,
align = "c"
) |>
kable_styling(
font_size = 10,
#bootstrap_options = "condensed",
latex_options = c("HOLD_position","scale_up") # "repeat_header"
) |>
add_header_above(
c(" " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1," " = 1,
"Diameter (cm)" = 2," " = 1, "Angle (percent)" = 4),
border_left = T, border_right = T, bold = F
) |>
add_header_above(
c(" " = 1, " " = 1," " = 1," " = 1," " = 1,"Coordinates" = 2, "DBH/DAB" = 4, " " = 1, " " = 1,
"Crown " = 4, "Height" = 5),
border_left = T, border_right = T, bold = F
) |>
row_spec(0, bold = F) |>
column_spec(1, border_left = T, bold = F, monospace = !vec_row1) |>
column_spec(2:9, monospace = !vec_row1) |>
column_spec(22, border_right = T) |>
row_spec(1, bold = F)
}
kbl_field_form[[1]]
if (nPages==2) kbl_field_form[[2]]
```