Learn R Programming

wizaRdry (version 0.6.4)

mongo.rune: Parse composite MongoDB collection into component data frames by variable prefix

Description

This function fetches a MongoDB collection containing multiple collections and separates it into individual data frames for each collection detected in the data. It identifies the appropriate identifier column (e.g., participantId, workerId) and splits the data based on column name prefixes.

Usage

mongo.rune(collection, prefix = NULL, db_name = NULL, lower = TRUE)

Value

If prefix is specified, returns a single dataframe with that prefix. Otherwise, creates multiple dataframes in the global environment, one for each survey detected in the data. Each dataframe is named after its survey prefix.

Arguments

collection

Character string specifying the Mongo collection

prefix

Character string; default NULL, if specified returns only the dataframe with this prefix

db_name

Character string specifying the Mongo database

lower

default TRUE convert prefixes to lower case

Details

The function performs the following steps:

  • Retrieves the raw Qualtrics data using the getSurvey() function

  • Identifies which identifier column to use (participantId, workerId, PROLIFIC_PID, or src_subject_id)

  • Determines survey prefixes by analyzing column names

  • Creates separate dataframes for each survey prefix found

  • Assigns each dataframe to the global environment with names matching the survey prefixes

Examples

Run this code
if (FALSE) {
# Parse a MongoDB collection into its component dataframes
mongo.rune("combined_surveys")

# After running, access individual survey dataframes directly:
head(pss)  # Access the PSS survey dataframe
head(cesd) # Access the CESD survey dataframe

# Parse a single survey from composite collection
rgpts <- mongo.rune("combined_surveys", prefix = "rgpts")
}

Run the code above in your browser using DataLab