-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathwrite_eml.R
34 lines (31 loc) · 1.07 KB
/
write_eml.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' write_eml
#'
#' write_eml
#' @param eml an emld class object
#' @param file file name to write XML.
#' @param namespaces named character vector of additional XML namespaces to use.
#' @param ns root namespace abbreviation
#' @param ... additional arguments to \code{\link{write_xml}}
#' @return If file is not specified, the result is a character string containing
#' the resulting XML content. Otherwise return silently.
#' @export
#' @importFrom uuid UUIDgenerate
#' @importFrom xml2 write_xml xml_set_namespace
#' @examples
#' f <- system.file("extdata", "example.xml", package = "emld")
#' eml <- read_eml(f)
#' write_eml(eml, "test.xml")
#' eml_validate("test.xml")
#' unlink("test.xml") # clean up
write_eml <- function(eml,
file,
namespaces = NULL,
ns = "eml",
...) {
## FIXME, insist on a packageId, or consider validation which can ignore id?
if (is.null(eml$packageId)) {
eml$packageId <- uuid::UUIDgenerate()
eml$system <- "uuid"
}
emld::as_xml(eml, file, ns = ns)
}