Functions for extracting information for Rmd nodes.
Usage
rmd_node_label(x, ...)
rmd_node_type(x, ...)
rmd_node_length(x, ...)
rmd_node_content(x, ...)
rmd_node_attr(x, attr, ...)
rmd_node_engine(x, ...)
rmd_node_options(x, ...)
rmd_node_code(x, ...)
Value
rmd_node_label()
- returns a character vector of node labels, nodes without labels returnNA
.rmd_node_type()
- returns a character vector of node types.rmd_node_length()
- returns an integer vector of node lengths (i.e. lines of code, lines of text, etc.), nodes without a length returnNA
.rmd_node_content()
- returns a character vector of node textual content, nodes without content returnNA
.rmd_node_attr()
- returns a list of node attribute values.rmd_node_engine()
- returns a character vector of chunk engines,NA
for all other node types.rmd_node_options()
- returns a list of chunk node options (named list),MULL
for all other node types.rmd_node_code()
- returns a list of chunk node code (character vector),NULL
for all other node types.
Examples
rmd = parse_rmd(system.file("examples/hw01.Rmd", package="parsermd"))
rmd_node_label(rmd)
#> [1] NA NA "load-packages" NA
#> [5] NA NA NA NA
#> [9] NA NA NA "plot-dino"
#> [13] NA "cor-dino" NA NA
#> [17] NA NA "plot-star" NA
#> [21] "cor-star"
rmd_node_type(rmd)
#> [1] "rmd_yaml" "rmd_heading" "rmd_chunk" "rmd_heading" "rmd_markdown"
#> [6] "rmd_heading" "rmd_markdown" "rmd_heading" "rmd_markdown" "rmd_heading"
#> [11] "rmd_markdown" "rmd_chunk" "rmd_markdown" "rmd_chunk" "rmd_heading"
#> [16] "rmd_markdown" "rmd_heading" "rmd_markdown" "rmd_chunk" "rmd_markdown"
#> [21] "rmd_chunk"
rmd_node_content(rmd)
#> [1] NA
#> [2] NA
#> [3] "library(tidyverse) \nlibrary(datasauRus)"
#> [4] NA
#> [5] "list(\"Based on the help file, how many rows and how many columns does the `datasaurus_dozen` file have? What are the variables included in the data frame? Add your responses to your lab report. When you're done, commit your changes with the commit message \\\"Added answer for Ex 1\\\", and push.\")\nlist()"
#> [6] NA
#> [7] "list(\"(Type your answer to Exercise 1 here. This exercise does not require any R code.)\")\nlist()"
#> [8] NA
#> [9] "list(\"Plot `y` vs. `x` for the `dino` dataset. Then, calculate the correlation coefficient between x and y for this dataset.\")\nlist()"
#> [10] NA
#> [11] "list(\"(The answers for this Exercise are given for you below. But you should clean up some of the narrative so that it only includes what you want to turn in.)\")\nlist()\nlist(\"First let's plot the data in the dino dataset:\")\nlist()"
#> [12] "dino_data <- datasaurus_dozen %>%\n filter(dataset == \"dino\")\n\nggplot(data = dino_data, mapping = aes(x = x, y = y)) +\n geom_point()"
#> [13] "list(\"And next calculate the correlation between `x` and `y` in this dataset:\")\nlist()"
#> [14] "dino_data %>%\n summarize(r = cor(x, y))"
#> [15] NA
#> [16] "list(\"Plot `y` vs. `x` for the `star` dataset. You can (and should) reuse code we introduced above, just replace the dataset name with the desired dataset. Then, calculate the correlation coefficient between x and y for this dataset. How does this value compare to the r of dino?\")\nlist()"
#> [17] NA
#> [18] "list(\"(Add code and narrative as needed. Note that the R chunks are labeled with `plot-star` and `cor-star` to provide spaces to place the code for plotting and calculating the correlation coefficient. To finish, clean up the narrative by removing these instructions.)\")\nlist()\nlist(\"Blah blah blah...\")\nlist()"
#> [19] ""
#> [20] "list(\"I'm some text, you should replace me with more meaningful text...\")\nlist()"
#> [21] ""
rmd_node_attr(rmd, "level")
#> [[1]]
#> NULL
#>
#> [[2]]
#> [1] 3
#>
#> [[3]]
#> NULL
#>
#> [[4]]
#> [1] 3
#>
#> [[5]]
#> NULL
#>
#> [[6]]
#> [1] 4
#>
#> [[7]]
#> NULL
#>
#> [[8]]
#> [1] 3
#>
#> [[9]]
#> NULL
#>
#> [[10]]
#> [1] 4
#>
#> [[11]]
#> NULL
#>
#> [[12]]
#> NULL
#>
#> [[13]]
#> NULL
#>
#> [[14]]
#> NULL
#>
#> [[15]]
#> [1] 3
#>
#> [[16]]
#> NULL
#>
#> [[17]]
#> [1] 4
#>
#> [[18]]
#> NULL
#>
#> [[19]]
#> NULL
#>
#> [[20]]
#> NULL
#>
#> [[21]]
#> NULL
#>
rmd_node_engine(rmd)
#> [1] NA NA "r" NA NA NA NA NA NA NA NA "r" NA "r" NA NA NA NA "r"
#> [20] NA "r"
rmd_node_options(rmd)
#> [[1]]
#> NULL
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> [[3]]$message
#> [1] "FALSE"
#>
#>
#> [[4]]
#> NULL
#>
#> [[5]]
#> NULL
#>
#> [[6]]
#> NULL
#>
#> [[7]]
#> NULL
#>
#> [[8]]
#> NULL
#>
#> [[9]]
#> NULL
#>
#> [[10]]
#> NULL
#>
#> [[11]]
#> NULL
#>
#> [[12]]
#> [[12]]$fig.height
#> [1] "3"
#>
#> [[12]]$fig.width
#> [1] "6"
#>
#>
#> [[13]]
#> NULL
#>
#> [[14]]
#> named list()
#>
#> [[15]]
#> NULL
#>
#> [[16]]
#> NULL
#>
#> [[17]]
#> NULL
#>
#> [[18]]
#> NULL
#>
#> [[19]]
#> named list()
#>
#> [[20]]
#> NULL
#>
#> [[21]]
#> named list()
#>
rmd_node_code(rmd)
#> [[1]]
#> NULL
#>
#> [[2]]
#> NULL
#>
#> [[3]]
#> [1] "library(tidyverse) " "library(datasauRus)"
#>
#> [[4]]
#> NULL
#>
#> [[5]]
#> NULL
#>
#> [[6]]
#> NULL
#>
#> [[7]]
#> NULL
#>
#> [[8]]
#> NULL
#>
#> [[9]]
#> NULL
#>
#> [[10]]
#> NULL
#>
#> [[11]]
#> NULL
#>
#> [[12]]
#> [1] "dino_data <- datasaurus_dozen %>%"
#> [2] " filter(dataset == \"dino\")"
#> [3] ""
#> [4] "ggplot(data = dino_data, mapping = aes(x = x, y = y)) +"
#> [5] " geom_point()"
#>
#> [[13]]
#> NULL
#>
#> [[14]]
#> [1] "dino_data %>%" " summarize(r = cor(x, y))"
#>
#> [[15]]
#> NULL
#>
#> [[16]]
#> NULL
#>
#> [[17]]
#> NULL
#>
#> [[18]]
#> NULL
#>
#> [[19]]
#> [1] ""
#>
#> [[20]]
#> NULL
#>
#> [[21]]
#> [1] ""
#>