xpath2frame: Extract Indexed Values from XML

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

For recovered XML values, these functions maintain context by returning data frame columns that show the parentage of each value.

Usage

 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
xpath2frame(
	x, 
	doc, 
	simplify = TRUE, 
	sort = TRUE, 
	nodebase = 'node',
	namespaces = FALSE,
	...
)

xlog(
	run, 
	project = getwd(), 
	rundir = filename(project, run), 
	file = filename(rundir, run, ".xml"), 
	xpath = c(
	"/output/nonmem/problem/problem_title",
	"/output/nonmem/problem/estimation/estimation_method", 
	"/output/nonmem/problem/estimation/estimation_title", 
	"/output/nonmem/problem/estimation/termination_status", 
	"/output/nonmem/problem/estimation/final_objective_function", 
	"/output/nonmem/problem/estimation/theta/val", 
	"/output/nonmem/problem/estimation/omega/row/col", 
	"/output/nonmem/problem/estimation/sigma/row/col"
	), 
	includeFile = NULL, 
	simplify = TRUE, 
	sort = TRUE, 
	nodebase = 'node',
	namespaces = FALSE,
	...
)

Arguments

x

a character vector of xpath expressions; omit namespace specifications if namespaces is FALSE

doc

an xml file path, a parsed xml tree, or a character vector to be parsed

simplify

whether to simplify the output by dropping static columns and stacking flag columns

sort

whether to sort the result

nodebase

a suggested base name for the stacking column; will be incremented using .n until unique

namespaces

whether to retain namespaces in parsed documents

run

character vector: run names

project

NONMEM project directory

rundir

character vector of run directories, normally constructed from run names and project directory

file

character vector of xml filenames, normally constructed from run names and run directories

xpath

character vector of xpath expressions

includeFile

xlog drops the column with the file name if it can recover the run name; includeFile=TRUE retains file name

...

extra arguments, ignored or passed

Details

xmlValue.XMLAttributeValue is defined to support searches for attributes.

A keyed data frame is returned, optionally sorted. The key is all columns except 'value'. If simplify is FALSE, it has columns representing every element of every search path. For xlog, it also has file and run (or file.1, run.1, etc. if these columns were already present).

If simplify is TRUE, columns with only one unique value are dropped. Also, a column named like nodebase (e.g. node, or node.1, etc., if node is already present) is introduced. Columns with exactly one unique value other than NA are dropped after placing the column name in corresponding rows of node. Columns beginning with nodebase come first, and therefore have priority when sorting.

By default, namespaces are stripped from parsed XML, and so do not need to be retained in xpath expressions. Alternatively, specify namespaces=TRUE and include namespaces in xpath expressions. See examples.

Value

object with class c('keyed','data.frame')

Note

As per advice in the XML package: use of absolute xpath expressions may result in faster searches: e.g. "/output/nonmem/problem/problem_title" not "//problem_title".

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

 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
xpath2frame(
  '/nm:output/nm:nonmem/nm:problem/nm:estimation/nm:monitor/nm:obj',
  system.file('example/project/nonmem/1005/1005.xml',package='metrumrg'),
  namespaces = TRUE
)
libxmlVersion()
## Not run: 
# libxml 2.8 (others?) may be problematic. You can switch to full path notation
# as above, and use 'namespaces=TRUE' (not the default).
x <- xpath2frame(
  c(
    '/output/nonmem/problem/estimation/monitor/obj/@iteration',
    '/output/nonmem/problem/estimation/monitor/obj'
  ),
  system.file('example/project/nonmem/1005/1005.xml',package='metrumrg')
)
x
cast(x,obj~node)


xpath2frame(
  c(
    '/output/nonmem/problem/estimation/theta/val',
    '/output/nonmem/problem/estimation/omega/row/col',
    '/output/nonmem/problem/estimation/sigma/row/col'
  ),
  system.file('example/project/nonmem/1005/1005.xml',package='metrumrg')
)
project <- system.file('example/project/nonmem',package='metrumrg')
xlog(1005:1006,project = project)

## End(Not run)

metrumrg documentation built on May 2, 2019, 5:55 p.m.