-
Notifications
You must be signed in to change notification settings - Fork 0
/
abmidata02-metadata.Rmd
73 lines (66 loc) · 1.98 KB
/
abmidata02-metadata.Rmd
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
---
title: "Tables and Metadata"
author: "Alberta Biodiversity Monitoring Institute"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Tables and Metadata}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup,include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## load package
suppressPackageStartupMessages({
library(abmidata)
library(knitr)
})
## get table names
n <- ad_get_table_names()
n <- n[order(names(n))]
## metadata
l2 <- list.files("../metadata/pdf")
l2x <- gsub("TMP_", "", l2)
l2x <- gsub("RAW_", "", l2x)
f2 <- function(i) which(startsWith(l2x, i))
p <- sapply(names(n), f2)
p1 <- p[sapply(p, length) > 0]
n <- n[!startsWith(names(n), "C") & names(n) %in% names(p1)]
## get table heads
x <- list()
for (i in names(n)) {
cat("\n", i)
x[[i]] <- try(ad_get_table_data(i, take=5L), silent=TRUE)
if (inherits(x[[i]], "try-error"))
cat("\tFAILED") else cat("\tOK")
}
OK <- !sapply(x, inherits, "try-error")
nOK <- n[OK]
pOK <- p1[names(nOK)]
xOK <- x[names(nOK)]
```
This article provides a description of the tables that can be accessed via the abmidata R package and the ABMI public data API.
```{r tabs,results = 'asis',echo=FALSE,warning=FALSE,message=FALSE}
stub <- "https://github.com/ABbiodiversity/abmidata/raw/master/metadata/pdf/"
for (j in seq_along(nOK)) {
id <- names(nOK)[j]
descr <- unname(gsub(paste0(id, " "), "", nOK[j]))
PDF <- pOK[[j]]
cat("### ", id, ": ", descr, "\n\n",
"Get the table as: `abmidata::ad_get_table(\"", id, "\")`\n\n", sep="")
if (length(PDF) == 1) {
cat("Metadata: [", gsub("\\.pdf", "", l2[PDF]),
"](", stub, utils::URLencode(l2[PDF]), ")\n", sep="")
} else {
cat("Metadata:\n\n")
for (k in seq_along(PDF))
cat("- [", gsub("\\.pdf", "", l2[PDF[k]]),
"](", stub, utils::URLencode(l2[PDF[k]]), ")\n", sep="")
}
cat("\n", sep="")
print(kable(xOK[[j]], caption=paste0("Head of table ", id)))
cat("\n", sep="")
}
```