knitr::opts_chunk$set( collapse = TRUE, comment = "#>", dpi=60 )
df2yaml
is an R package distributed as part of the CRAN.
To install the package, start R and enter:
# install via CRAN install.package("df2yaml") # install via Github # install.package("remotes") #In case you have not installed it. remotes::install_github("showteeth/df2yaml")
In general, it is recommended to install from Github repository (update more timely).
Once df2yaml
is installed, it can be loaded by the following command.
library(df2yaml)
The goal of df2yaml
is simplify the process of converting dataframe to YAML. The dataframe with multiple key columns and one value column (this column can also contain key-value pair(s)) will be converted to multi-level hierarchy.
Load the test data, this test data contains two key columns (paras
and subcmd
) and one value column, the value column also contains key and value pair(s) separated by ":".
# library library(df2yaml) # load test file test_file <- system.file("extdata", "df2yaml_l3.txt", package = "df2yaml") test_data = read.table(file = test_file, header = T, sep = "\t") head(test_data) # output yaml string yaml_res = df2yaml(df = test_data, key_col = c("paras", "subcmd"), val_col = "values") cat(yaml_res)
Convert above dataframe to YAML:
yaml_res = df2yaml(df = test_data, key_col = c("paras", "subcmd"), val_col = "values") cat(yaml_res)
There is no limit to the number of key columns used to convert.
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.