如发现问题或者有建议,欢迎提交 Issue
rlist包是任坤开发,用于处理非表列数据(non-tabular
data),常见数据类型为JSON和YAML字段。
pipeline的选择
%>%also works with rlist functions. However, in some cases, the operator may impose conflicting interpretation on.symbol to cause unexpected error.[@Ren2016]
这里会考虑使用pipeR:%>>%:。
JSON格式
In the coming tutorial pages, we will mainly use JSON data to demonstrate the features and examples of rlist package.
[]creates a unnamed node array.{}creates a named node list."key" : valuecreates a key-value pair wherevaluecan be a number, a string, a[]array, or a{}list.
rlist package imports jsonlite package to
read/write JSON data.
YAML格式
rlistalso imports yaml package to read/writeYAMLdata.
- Name: Ken
Age: 24
Interests:
- reading
- music
- movies
Expertise:
R: 2
CSharp: 4
Python: 3
- Name: James
Age: 25
Interests:
- sports
- music
Expertise:
R: 3
Java: 2
Cpp: 5
- Name: Penny
Age: 24
Interests:
- movies
- reading
Expertise:
R: 1
Cpp: 4
Python: 2数据来源于 @Ren2016 https://renkun-ken.github.io/rlist-tutorial/data/sample.yaml 常见于RMarkdown文档的开头申明。
博客可以使用这个来提取yaml数据
举例
## Error in `library()`:
## ! there is no package called 'tidyverse'
## Error in `library()`:
## ! there is no package called 'rlist'
## Error in `list.load()`:
## ! could not find function "list.load"
## Error:
## ! object 'people' not found
NOTE:
str()previews the structure of an object. We may use this function more often to avoid verbose representation of list objects.
这个函数展示很不错。
people %>%
map(
~ list(
name = .$Name
,age =
.$Age
,range =
.$Expertise %>%
as.numeric %>%
range %>%
as.character %>%
str_flatten('-')
)
) %>%
map(~glue::glue("{.$name}: {.$age} and has {.$range} year experience"))## Error in `people %>% map(~ list(name = .$Name, age = .$Age, range = .$Expertise %>%
## as.numeric %>% range %>% as.character %>% str_flatten("-"))) %>% map(~ glue::glue(
## "{.$name}: {.$age} and has {.$range} year experience"))`:
## ! could not find function "%>%"
这个可以用来出tutorial的题目。
filter
## Error in `people %>% list.filter(Age >= 25 & "music" %in% Interests) %>% map(~ .$Name)`:
## ! could not find function "%>%"
这个还没找好很好的替代方式。
list.findlist.findilist.firstlist.lastlist.takelist.skip
太多了,没什么好选择的。
是list.filter
的替代品,只反馈一部分的字段,因为json格式很大时,反馈时间很长。