Quick utility function to use str_replace with mutate(across()) to batch- rename subjects via pattern detection.

rename_viewr_characters(
  obj_name,
  target_column = "subject",
  pattern,
  replacement = ""
)

Arguments

obj_name

The input viewr object; a tibble or data.frame with attribute pathviewR_steps that includes "viewr"

target_column

The target column; defaults to "subject"

pattern

The (regex) pattern to be replaced

replacement

The replacement text. Must be a character

Value

A tibble or data frame in which subjects have been renamed according to the pattern and replacement supplied by the user.

See also

Author

Vikram B. Baliga

Examples

## Import the example Motive data included in the package motive_data <- read_motive_csv(system.file("extdata", "pathviewR_motive_example_data.csv", package = 'pathviewR')) ## Clean the file. It is generally recommended to clean up to the ## "gather" step before running rescale_tunnel_data(). motive_gathered <- motive_data %>% relabel_viewr_axes() %>% gather_tunnel_data() ## See the subject names unique(motive_gathered$subject)
#> [1] "device02" "device03" "device05"
## Now rename the subjects. We'll get rid of "device" and replace it ## with "subject" motive_renamed <- motive_gathered %>% rename_viewr_characters(target_column = "subject", pattern = "device", replacement = "subject") ## See the new subject names unique(motive_renamed$subject)
#> [1] "subject02" "subject03" "subject05"