rename_viewr_characters: Rename subjects in the data via pattern detection

View source: R/utility_functions.R

rename_viewr_charactersR Documentation

Rename subjects in the data via pattern detection

Description

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

Usage

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.

Author(s)

Vikram B. Baliga

See Also

Other data cleaning functions: gather_tunnel_data(), get_full_trajectories(), quick_separate_trajectories(), redefine_tunnel_center(), relabel_viewr_axes(), rotate_tunnel(), select_x_percent(), separate_trajectories(), standardize_tunnel(), trim_tunnel_outliers(), visualize_frame_gap_choice()

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)

## 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)

pathviewr documentation built on March 31, 2023, 5:47 p.m.