Apply protocol events from note files to a single room data frame (new software)
Source:R/processing.R
extract_note_info_new.RdReads a note file, extracts protocol events, applies any detected time drift, and updates the protocol column in the provided data frame. Designed for notes generated by the newer software version where all participants are in a single data frame.
Arguments
- df
data.frame Data frame containing at least a "datetime" column.
- notes_path
character Path to the note file containing protocol events.
- keywords_dict
List, A dictionary of keywords used to extract protocol events from a note file. Each entry should be a named list with:
- keywords
A character vector of keywords or phrases to match in the note comment. Matching is case-insensitive.
- value
Numeric protocol value to assign when the keyword is detected.
- type
Optional character, either "instant" or omitted. "instant" events are applied at the specified timestamp and revert to the previous protocol immediately after. Non-instant events set the protocol until another event occurs.
Behavior rules:
- Non-instant events
Set the protocol value from their timestamp until another event overwrites it or until a stop keyword sets it to 0.
- Instant events
Apply only at the timestamp of the note line, then revert to the protocol that was active immediately before.
- Stop keywords
Always set the protocol to 0, regardless of previous state, unless overridden by an instant event.
If
NULL, a default set of keywords is used.
Examples
df <- data.frame(datetime = as.POSIXct(c("2023-11-13 22:40:00", "2023-11-13 22:50:00")))
note_file <- system.file("extdata", "note_v2.txt", package = "wrictools")
df_updated <- extract_note_info_new(df, note_file)
df_updated
#> datetime protocol
#> 1 2023-11-13 22:37:46 0
#> 2 2023-11-13 22:47:46 0