rokogiri: An XML generator DSL in R, inspired by Ruby's Nokogiri.

Description Usage Arguments Value Examples

View source: R/rokogiri.R

Description

An XML generator DSL in R, inspired by Ruby's Nokogiri.

Compile an R expression into XML.

Usage

1
rokogiri(expr, output_type = "xml", enclos = parent.frame())

Arguments

expr

expression. The R expression to compile to XML.

output_type

character. Either 'list' or 'xml'. By default, the latter.

enclos

environment. The enclosing environment to use for evaluating variables mentioned in the XML generation process. By default, parent.frame().

Value

a character string representing the compiled XML.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
xml <- rokogiri({
  note({
    to("Tove")
    from("Jani")
    heading("Reminder")
    msg("Don't forget me this weekend!")
  })
})

expected_xml <- "
  <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <msg>Don't forget me this weekend!</msg>
  </note>
"

remove_spacing <- function(x) { gsub("[ \n]", "", x) }
stopifnot(remove_spacing(xml) == remove_spacing(expected_xml))

robertzk/rokogiri documentation built on May 27, 2019, 11:37 a.m.