# Say we would like to generate an HTML website and want to use
# , and tags.
# The standard way of creating a node would be this:
(my_node <- XMLNode("div", "some content", class="important"))
# By using gen_tag_functions(), we can create some shortcut functions
# to get better readability for our code and save some typing:
gen_tag_functions(tags=c("a", "div", "p"))
# We can now use div_() instead of XMLNode("div"):
(my_node2 <- div_("some content", class="important"))
# It also works for nested tags:
(my_node3 <- div_(a_(href="foo", "some content")))
# If you don't want these functions filling up your .GlobalEnv,
# you can also put them in an attached environment, e.g.
attach(list(), name="XiMpLe_wrappers")
gen_tag_functions(tags=c("head", "body"), envir=as.environment("XiMpLe_wrappers"))
Run the code above in your browser using DataLab