Merge pull request #355 from jcheng5/bugfix/null-children

Ignore NULL tag elements
This commit is contained in:
Yihui Xie
2014-01-08 18:51:20 -08:00
3 changed files with 15 additions and 1 deletions

View File

@@ -126,7 +126,7 @@ tag <- function(`_tag_name`, varArgs) {
# Unnamed arguments are flattened and added as children.
# Use unname() to remove the names attribute from the list, which would
# consist of empty strings anyway.
children <- flattenTags(unname(varArgs[!named_idx]))
children <- dropNullsOrEmpty(flattenTags(unname(varArgs[!named_idx])))
# Return tag data structure
structure(

View File

@@ -60,6 +60,14 @@ dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE=logical(1))]
}
nullOrEmpty <- function(x) {
is.null(x) || length(x) == 0
}
# Given a vector or list, drop all the NULL items in it
dropNullsOrEmpty <- function(x) {
x[!vapply(x, nullOrEmpty, FUN.VALUE=logical(1))]
}
knownContentTypes <- Map$new()
knownContentTypes$mset(
html='text/html; charset=UTF-8',