data_frag | R Documentation |
Create a xml_fragment()
from a data.frame, in which each row is a set of xml elements (columns).
data_frag(df, row_tags = "row", .attr = NULL)
df |
data frame that will be stored as set of xml elements |
row_tags |
|
.attr |
optional |
xml_fragment()
object
Other xml_fragment:
add_child_fragment()
,
as.character.xml_fragment()
,
as_frag()
,
as_xml_nodeset()
,
frag()
,
xml_fragment()
persons <- data.frame(
name = c("John Doe", "Jane Doe"),
age = c(30, 25),
stringsAsFactors = FALSE
)
df <- data_frag(persons, row_tag = "person")
print(df)
# setting ids on rows
persons <- data.frame(
name = c("John Doe", "Jane Doe"),
age = c(30, 25),
id = c("p1", "p2"),
stringsAsFactors = FALSE
)
df <- data_frag(
persons[1:2],
row_tag = "person",
.attr = persons[3]
)
print(df)
# turning it into a document
doc <- xml_doc("study", id = "1") / frag(
source = "homeless db",
data = df
)
cat(as.character(doc))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.