This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.Rmd
170 lines (133 loc) · 4.9 KB
/
README.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
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
finch
=====
```{r echo=FALSE}
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
lines <- options$output.lines
if (is.null(lines)) {
return(hook_output(x, options)) # pass to default hook
}
x <- unlist(strsplit(x, "\n"))
more <- "..."
if (length(lines) == 1) { # first n lines
if (length(x) > lines) {
# truncate the output, but add ....
x <- c(head(x, lines), more)
}
} else {
x <- c(if (abs(lines[1])>1) more else NULL,
x[lines],
if (length(x)>lines[abs(length(lines))]) more else NULL
)
}
# paste these lines together
x <- paste(c(x, ""), collapse = "\n")
hook_output(x, options)
})
knitr::opts_chunk$set(
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>"
)
```
[![R-check](https://github.com/ropensci/finch/workflows/R-check/badge.svg)](https://github.com/ropensci/finch/actions?query=workflow%3AR-check)
[![cran checks](https://cranchecks.info/badges/worst/finch)](https://cranchecks.info/pkgs/finch)
[![codecov](https://codecov.io/gh/ropensci/finch/branch/master/graph/badge.svg)](https://codecov.io/gh/ropensci/finch)
[![cran version](https://www.r-pkg.org/badges/version/finch)](https://cran.r-project.org/package=finch)
`finch` parses Darwin Core simple and archive files
Docs: <https://docs.ropensci.org/finch/>
* Darwin Core description at Biodiversity Information Standards site <http://rs.tdwg.org/dwc.htm>
* Darwin Core at Wikipedia <https://en.wikipedia.org/wiki/Darwin_Core>
## Install
Stable version
```{r eval=FALSE}
install.packages("finch")
```
Development version, from GitHub
```{r eval=FALSE}
remotes::install_github("ropensci/finch")
```
```{r}
library("finch")
```
## Parse
To parse a simple darwin core file like
```
<?xml version="1.0" encoding="UTF-8"?>
<SimpleDarwinRecordSet
xmlns="http://rs.tdwg.org/dwc/xsd/simpledarwincore/"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:dwc="http://rs.tdwg.org/dwc/terms/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://rs.tdwg.org/dwc/xsd/simpledarwincore/ ../../xsd/tdwg_dwc_simple.xsd">
<SimpleDarwinRecord>
<dwc:occurrenceID>urn:catalog:YPM:VP.057488</dwc:occurrenceID>
<dc:type>PhysicalObject</dc:type>
<dc:modified>2009-02-12T12:43:31</dc:modified>
<dc:language>en</dc:language>
<dwc:basisOfRecord>FossilSpecimen</dwc:basisOfRecord>
<dwc:institutionCode>YPM</dwc:institutionCode>
<dwc:collectionCode>VP</dwc:collectionCode>
<dwc:catalogNumber>VP.057488</dwc:catalogNumber>
<dwc:individualCount>1</dwc:individualCount>
<dwc:locationID xsi:nil="true"/>
<dwc:continent>North America</dwc:continent>
<dwc:country>United States</dwc:country>
<dwc:countryCode>US</dwc:countryCode>
<dwc:stateProvince>Montana</dwc:stateProvince>
<dwc:county>Garfield</dwc:county>
<dwc:scientificName>Tyrannosourus rex</dwc:scientificName>
<dwc:genus>Tyrannosourus</dwc:genus>
<dwc:specificEpithet>rex</dwc:specificEpithet>
<dwc:earliestPeriodOrHighestSystem>Creataceous</dwc:earliestPeriodOrHighestSystem>
<dwc:latestPeriodOrHighestSystem>Creataceous</dwc:latestPeriodOrHighestSystem>
<dwc:earliestEonOrHighestEonothem>Late Cretaceous</dwc:earliestEonOrHighestEonothem>
<dwc:latestEonOrHighestEonothem>Late Cretaceous</dwc:latestEonOrHighestEonothem>
</SimpleDarwinRecord>
</SimpleDarwinRecordSet>
```
This file is in this package as an example file, get the file, then `simple()`
```{r}
file <- system.file("examples", "example_simple_fossil.xml", package = "finch")
out <- simple_read(file)
```
Index to `meta`, `dc` or `dwc`
```{r}
out$dc
```
## Parse Darwin Core Archive
To parse a Darwin Core Archive like can be gotten from GBIF use `dwca_read()`
There's an example Darwin Core Archive:
```{r}
file <- system.file("examples", "0000154-150116162929234.zip", package = "finch")
(out <- dwca_read(file, read = TRUE))
```
List files in the archive
```{r output.lines=1:10}
out$files
```
High level metadata for the whole archive
```{r output.lines=1:20}
out$emlmeta
```
High level metadata for each data file, there's many files, but we'll just look at one
```{r}
hm <- out$highmeta
head( hm$occurrence.txt )
```
You can get the same metadata as above for each dataset that went into the tabular dataset downloaded
```{r eval=FALSE}
out$dataset_meta[[1]]
```
View one of the datasets, brief overview.
```{r}
head( out$data[[1]][,c(1:5)] )
```
You can also give `dwca()` a local directory, or url that contains a Darwin Core Archive.
## Meta
* Please [report any issues or bugs](https://github.com/ropensci/finch/issues).
* License: MIT
* Get citation information for `finch` in R doing `citation(package = 'finch')`
* Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.
[![rofooter](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)