devtools::install_github("nokut/nokutdb")
library(nokutdb)
# Import all CSV files from a directory
results <- import_survey_data("path/to/csv/files")
# Check import results
print(sprintf("Imported %d rows, %d failed",
results$successful, results$failed))The importer automatically looks for label files with the naming convention filename_labels.csv in the same directory. For example, if your data file is called survey_responses.csv, the importer will look for survey_responses_labels.csv.
Label files should have at least two columns:
variable: The variable name that matches the column in the data file label: The label text for that variable
Example label file content:
variable,label
q1,"How satisfied are you with the course?"
q2,"How useful did you find the learning materials?"
q3,"How would you rate the teaching quality?"# Import without labels
results <- import_survey_data("path/to/csv/files", import_labels = FALSE)The importer expects CSV files with the following characteristics:
First row contains variable names Each subsequent row contains one respondent's answers Values can be numeric or text Values can include labels in the format "value|label" (e.g., "5|Very satisfied")
The importer interacts with the following database tables:
surveys: Stores information about each survey survey_fields: Stores the fields (questions) for each survey respondents: Stores respondent information survey_responses: Links respondents to surveys response_values: Stores the actual response values
Labels are stored in the survey_fields table in the database. If a data value includes a label (in the format "value|label"), the importer will:
- Store the value in the value_text or value_number column of response_values
- Extract just the value part for storage
R 3.5.0 or later RMySQL package DBI package Access to a MySQL/MariaDB database with the NOKUT survey schema
If you encounter issues with the import process:
Check that your database connection is correctly configured Verify that your CSV files follow the expected format Ensure your database schema matches the expected structure For large imports, consider increasing the R memory limit with memory.limit(size=4000)