-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
137 lines (104 loc) · 3.64 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![R-CMD-check](https://github.com/SwissStatsR/dcatapchr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/SwissStatsR/dcatapchr/actions/workflows/R-CMD-check.yaml)
[![:name status badge](https://swissstatsr.r-universe.dev/badges/:name)](https://swissstatsr.r-universe.dev/)
[![dcatapchr status badge](https://swissstatsr.r-universe.dev/badges/dcatapchr)](https://swissstatsr.r-universe.dev/dcatapchr)
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# dcatapchr
The goal of dcatapchr is to create a metadata catalog compatible with the
DCAT-AP CH standard.
Basically, a catalog consists of one or more datasets, and each dataset has one or more distributions (see https://www.dcat-ap.ch/releases/2.0/dcat-ap-ch.html and https://handbook.opendata.swiss/de/content/glossar/bibliothek/dcat-ap-ch.html).
## Installation
You can install the development version of dcatapchr like so:
``` r
remotes::install_github("SwissStatsR/dcatapchr")
```
Or from the `swissstatsr.r-universe.dev`:
```r
install.packages("dcatapchr", repos = "https://swissstatsr.r-universe.dev")
```
## Example
In the example below, a catalog is created with a dataset with 3 distributions.
```{r example}
library(dcatapchr)
# Create the metadata of a dataset with 3 distributions
# First create the 3 distributions
distributions <- c(
dcat_distribution(
issued = dct_issued("2021-10-14"),
access_url = dcat_accessURL(
"https://www3.ti.ch/DFE/DR/USTAT/allegati/cubo/cubi_POL_01_xlsx.zip"
),
license = dct_license2(
"NonCommercialAllowed-CommercialAllowed-ReferenceRequired"
)
),
dcat_distribution(
issued = dct_issued("2021-10-14"),
access_url = dcat_accessURL(
"https://www3.ti.ch/DFE/DR/USTAT/allegati/cubo/cubi_POL_01_px.zip"
),
license = dct_license2(
"NonCommercialAllowed-CommercialAllowed-ReferenceRequired"
)
),
dcat_distribution(
issued = dct_issued("2021-10-14"),
access_url = dcat_accessURL(
"https://www3.ti.ch/DFE/DR/USTAT/allegati/cubo/cubi_POL_01_csv.zip"
),
licence = dct_license2(
"NonCommercialAllowed-CommercialAllowed-ReferenceRequired"
)
)
)
distributions
# Then create the dataset with the 3 distributions created above
description <- readLines(
system.file(
"cubi_POL_01_INFORMAZIONI.txt", package = "dcatapchr"
), encoding = "UTF-8"
)
description <- strwrap(description, width = 80)
description <- paste(description, collapse = "\n")
# Substitute & with & in urls
description <- gsub("&", "&", description, fixed = TRUE)
dataset <- dcat_dataset(
title = dct_title(
title = "Partecipazione alle elezioni del Consiglio di Stato, per comune, in Ticino, dal 1921 al 2011",
language = "it"
),
description = dct_description(
description = description,
language = "it"
),
publisher = dct_publisher(publisher = "https://www.ti.ch/ustat", foaf_name = "Ustat"),
contactPoint = dcat_contactPoint(),
identifier = dct_identifier(),
distribution = distributions
)
# dataset
# And finally put the dataset in a catalog
catalog <- dcat_catalog(
catalog_endpoint = "https://www3.ti.ch/DFE/DR/USTAT/allegati/digitale/catalogo_ustat.rdf",
datasets = dataset
)
head(catalog, n = 15)
tail(catalog, n = 20)
```
Export to an rdf file (with UNIX line endings):
```{r eval=FALSE}
# f <- file("./catalogo_ustat.rdf", "wb")
# writeLines(catalog, con = f, useBytes = TRUE)
# close(f)
write_unix(catalog, filename = "catalogo_ustat.rdf")
```