-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvy.R
38 lines (26 loc) · 989 Bytes
/
csvy.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
library(gapminder)
library(dplyr)
library(readr)
library(csvy)
write_csv(gapminder, path = "data/gapminder_metadata.csvy")
read_csv("data/gapminder_metadata.csvy")
gapminder_after <- read_csvy("data/gapminder_metadata.csvy")
glimpse(gapminder_after)
head(gapminder_after)
str(gapminder_after)
# comment! this is a comment!
gap1 <- read.csv("data/gapminder_metadata.csvy", comment.char = "#")
glimpse(gap1)
write_csvy(gapminder, file = "data/gapminder_meta_write.csvy")
## example of writing metadata in R
gapminder %>%
mutate(country = as.character(country),
country = `attr<-`(country, "description",
"Name of the country")) %>%
write_csvy(file = "data/gapminder_meta_write.csvy")
## another way
gapminder_chr_country <- gapminder %>%
mutate(country = as.character(country))
attr(gapminder_chr_country$country, which = "title") <- "Country name"
gapminder_chr_country %>%
write_csvy("data/gapminder_meta_write.csvy")