Skip to contents

Check if the $Chats data frame includes both session-related variables and participant-related variables that appear multiple times. This may occur when data from different oTree versions, which use different variable names, are combined.

If desired, the function can merge these variables, storing the data using the newer oTree version's variable names and removing the outdated variables.

Usage

messy_chat(
  oTree,
  combine = FALSE,
  session = TRUE,
  participant = TRUE,
  info = FALSE
)

Arguments

oTree

A list of data frames that were created by import_otree.

combine

Logical. TRUE if all variables referring to the session code should be merged and/or all variables referring to participant code should be merged in case data of several versions of oTree are used.

session

Logical. TRUE if all variables referring to the session code should be checked and merged. Merging only works if combine = TRUE.

participant

Logical. TRUE if all variables referring to the participant code should be checked and merged. Merging only works if combine = TRUE.

info

Logical. TRUE if a brief information on the process should be printed.

Value

This function searches for multiple variables related to the session code or the participant code in the $Chats data frame. which can occur when data from both old and new oTree versions are used.

If combine = FALSE, the function will throw an error if such variables are found.

If combine = TRUE, the function will not throw an error if such variables are found. Instead, it automatically combines the variables into new variables and adds them to the original $Chats data frame. This function then returns a duplicate of the original oTree list but with the $Chats data frame modified.

The new variables are called participant_code and session_code.

Examples

# Set data folder first
withr::with_dir(system.file("extdata", package = "gmoTree"), {

# Import all oTree files in this folder and its subfolders
oTree <- import_otree()
})
#> Warning: You have stored all_apps_wide globally but also room-specific. This function will import both of them. (Globally, the files are saved as "all_apps_wide_." Room-specific, the files are saved as "All apps - wide-" or "all_apps_wide-.") After importing the data, make sure nothing is there twice! (Advice: You may use delete_duplicate() to remove duplicate rows of all oTree data frames.

# Show all Chats column names
print(colnames(oTree$Chats))
#>  [1] "session_code"               "id_in_session"             
#>  [3] "participant_code"           "channel"                   
#>  [5] "nickname"                   "body"                      
#>  [7] "timestamp"                  "participant__session__code"
#>  [9] "participant__session_id"    "participant__id_in_session"
#> [11] "participant__code"         

# Run function
oTree <- messy_chat(oTree, combine = TRUE)

# Show all Chats column names again
print(colnames(oTree$Chats))
#> [1] "session_code"               "id_in_session"             
#> [3] "participant_code"           "channel"                   
#> [5] "nickname"                   "body"                      
#> [7] "timestamp"                  "participant__session_id"   
#> [9] "participant__id_in_session"