Learn R Programming

fhircrackr (version 2.1.1)

fhir_rm_tag: Remove a certain xml tag

Description

Removes a given xml tag from xml objects represented in a fhir_bundle_xml, fhir_bundle_list or character vector.

Usage

fhir_rm_tag(x, tag)

# S4 method for character fhir_rm_tag(x, tag)

# S4 method for fhir_bundle_xml fhir_rm_tag(x, tag)

# S4 method for fhir_bundle_list fhir_rm_tag(x, tag)

Value

An object of the same class as x where all tags matching the tag argument are removed.

Arguments

x

A fhir_bundle_xml or fhir_bundle_list object or a character vector containing xml objects.

tag

A character vector of length 1 containing the tag that should be removed, e.g. "div".

Details

In the example Hello<div>Please<p>Remove Me</p></div>World! one could for example remove the tag p, resulting in Hello<div>Please</div>World!or remove the div tag resulting in Hello World!.

See Also

fhir_rm_div()

Examples

Run this code

#Example 1: Remove tag from xmls in a character vector
string <- c("HelloPleaseRemove Me World!",
            "ABCD")

fhir_rm_tag(x = string, tag = "p")




#Example 2: Remove div tags in a single fhir bundle
bundle <- fhir_unserialize(patient_bundles)[[1]]

#example bundle contains html parts in div tags:
cat(toString(bundle))

#remove html parts
bundle_cleaned <- fhir_rm_tag(x = bundle, tag = "div")

#have a look at the result
cat(toString(bundle_cleaned))





#Example 3: Remove div tags in a list of fhir bundles
bundle_list <- fhir_unserialize(patient_bundles)


#remove html parts
bundle_list_cleaned <- fhir_rm_tag(x = bundle_list, tag = "div")

#check out how much the size of the bundle list is reduced by removing html
size_with_html <- sum(sapply(bundle_list, function(x)object.size(toString(x))))
size_without_html <- sum(sapply(bundle_list_cleaned, function(x)object.size(toString(x))))

size_without_html/size_with_html

Run the code above in your browser using DataLab