ox_xtract_group: Data for a group of items, as a tidy dataframe

Description Usage Arguments Value Examples

Description

Returns a tidy dataframe from a ox_all object, containing data for all items of the specified group. In the resulting dataframe, each item is a variable, and each row is an observation; dataframe variables are identified by their item_oid (or optionally, by their item_name), and are one of the following classes: Date, numeric, or character. Optionally, items with codelists can be defined as factor.

Usage

1
2
ox_xtract_group(ox_obj, group, define_factors = FALSE,
  use_item_names = FALSE)

Arguments

ox_obj

An object of class ox_all, as returned by ox::ox_all().

group

A group of items, as character value. Must be one of the group_oid values in ox_obj$metadata$group_def.

define_factors

A logical value. When TRUE, items with codelists are defined as factors using the codelist. Defaults to FALSE.

use_item_names

A logical value. When TRUE, item_name in ox_obj$metadata$item_def are used as variable names in the resulting dataframe. Othewise, item_oid are used. Defaults to FALSE.

Value

A dataframe with study, subject, event, form, group and group repeat keys, plus all items in group as variables.

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
# The example odm1.3 xml file address
my_file <- system.file("extdata",
                       "odm1.3_full_example.xml",
                       package = "ox",
                       mustWork = TRUE)

# Parsing the xml file
library(XML)
doc <- xmlParse(my_file)

# Create ox_all object
my_study <- ox_all(doc)

# Item groups
unique(my_study$metadata$group_def$group_oid)

# Extract data for a group
demo <- ox_xtract_group(my_study,
                        group = "IG_DEMO_DEMOGRAPHICDATA")
head(demo)

# Same, using item names to identify vars, and
# defining factors for items with codelist
demo_2 <- ox_xtract_group(my_study,
                          group = "IG_DEMO_DEMOGRAPHICDATA",
                          define_factors = TRUE,
                          use_item_names = TRUE)
head(demo_2)

acobos/ox documentation built on May 13, 2019, 12:17 p.m.