-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgap_eml.R
102 lines (66 loc) · 3.2 KB
/
gap_eml.R
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
library(dplyr)
library(EML)
library(gapminder)
# attributes --------------------------------------------------------------
attributes <- frame_data(
~attributeName, ~formatString, ~definition , ~unit, ~numberType, ~attributeDefinition,
"country" , NA, "country", NA, NA, "name of country",
"continent" , NA, "continent", NA, NA, "name of continent",
"year" , "YYYY", NA, NA, NA, "year of sample",
"lifeExp" , NA, NA, "number", "real", "life expentency at birth",
"pop" , NA, NA, "number", "real", "total population",
"gdpPercap" , NA, NA, "number", "real", "GDP per capita"
)
## what units can we use? consult:
# standardUnits <- get_unitList()
# standardUnits$units
# View(standardUnits$units)
# factors -----------------------------------------------------------------
## there are no factors in this dataset, but this is where you would put them!
attributeList <- set_attributes(as.data.frame(attributes),
col_classes = c("character", "character",
"Date",
"numeric", "numeric", "numeric"))
## as many col_classes as there are rows in attributes
## note that you need to coerce attributes back to data.frame
# dataTable: putting it together ------------------------------------------
readr::write_csv(gapminder, "data/gapminder.csv")
physical <- set_physical("data/gapminder.csv")
dataTable <- new("dataTable",
entityName = "gapminder.csv",
entityDescription = "Gapminder data",
physical = physical,
attributeList = attributeList)
# person ------------------------------------------------------------------
R_person <- as.person("John Doe <[email protected]")
ownername <-as(R_person, "creator")
contact <-
new("contact",
individualName = ownername@individualName,
electronicMail = ownername@electronicMailAddress,
# address =,
organizationName = "Gapminder",
phone = "000-000-0000")
# coverage ----------------------------------------------------------------
coverage <-
set_coverage(begin = '1952-01-01', end = '2007-01-01',
geographicDescription = "The world",
west = -10, east = 70,
north = 90, south = -90,
altitudeMin = 0, altitudeMaximum = 2000,
altitudeUnits = "meter")
# combining everything: dataset -------------------------------------------
dataset <- new("dataset",
title = "the title",
creator = ownername,
pubDate = "2016",
coverage = coverage,
contact = contact,
dataTable = dataTable)
eml <- new("eml",
packageId = "e2200f7b-1eea-426e-9be1-930671924e24", # from uuid::UUIDgenerate(),
system = "uuid", # type of identifier
dataset = dataset)
eml_validate(eml)
write_eml(eml, file = "gapminder.eml")
eml_view("gapminder.eml")