Title: | Read Data from 'LimeSurvey' |
---|---|
Description: | Read data from 'LimeSurvey' (<https://www.limesurvey.org/>) in a comfortable way. Heavily inspired by 'limer' (<https://github.com/cloudyr/limer/>), which lacked a few comfort features for me. |
Authors: | Maximilian Hagspiel [aut, cre, cph] |
Maintainer: | Maximilian Hagspiel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2024-11-29 08:53:28 UTC |
Source: | CRAN |
Convert a base64 representation of a CSV table into a 'data.frame' object.
base64_to_df(x)
base64_to_df(x)
x |
The base64-encoded CSV string |
A 'data.frame' object containing the data from 'x'.
Connect to 'LimeSurvey' instance via the RPC and a direct MySQL connection. Store the RPC session key in ‘options(’limesurvey_session_key')'. Store the MySQL connection object in ‘options(’limesurvey_mysql_connection')'. Store the RPC URL in ‘options(’limesurvey_api_url')'.
connect_to_limesurvey( api_url, limesurvey_username, limesurvey_password, mysql_host, mysql_port, mysql_dbname, mysql_username, mysql_password )
connect_to_limesurvey( api_url, limesurvey_username, limesurvey_password, mysql_host, mysql_port, mysql_dbname, mysql_username, mysql_password )
api_url |
URL to the 'LimeSurvey' RPC, e.g. 'http://localhost/index.php/admin/remotecontrol' |
limesurvey_username |
Username for the 'LimeSurvey' API |
limesurvey_password |
Password for the 'LimeSurvey' API |
mysql_host |
Hostname of the MySQL server used by 'LimeSurvey' |
mysql_port |
Port on which the MySQL server listens for connections |
mysql_dbname |
Name of the database on the MySQL server which is used by 'LimeSurvey' |
mysql_username |
Username for the MySQL server |
mysql_password |
Password for the MySQL server |
No return value, called for side effects
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) ## End(Not run)
Freshly exported data has all item-data columns as type "character". This function converts these columns to ideal types (e.g. integer). Currently simply converts all multiple-choice columns to integer. Future task: Add conversion to other data types as needed.
fix_column_data_types(df_in)
fix_column_data_types(df_in)
df_in |
The 'data.frame' object to fix. |
A 'data.frame' object containing the data from 'df_in' but with fixed column data types.
Get the answer options to a question with pre-defined answer options (e.g. a multiple choice question).
get_answer_options(question_code)
get_answer_options(question_code)
question_code |
Code by which to identify the question. Follows a dot-based naming scheme: <group title>.<subquestion title>. |
'data.frame' object with the columns 'code' and 'answer' in which each row represents one answer option where 'code' is the encoded value (as found in datasets exported by 'get_survey_data()' and 'answer' is the answer option text as seen by survey users).
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves the possible answer options. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) answer_options <- get_answer_options("bdi.01") ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves the possible answer options. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) answer_options <- get_answer_options("bdi.01") ## End(Not run)
Get the question text (e.g. "How have you been feeling?") to a question in the dataset.
get_question_text(question_code)
get_question_text(question_code)
question_code |
Code by which to identify the question. Follows a dot-based naming scheme: <group title>.<subquestion title>. |
'character' object containing the question text
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves the question text which was shown # to the user when answering the questionnaire. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) q_text <- get_question_text("bdi.01") ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves the question text which was shown # to the user when answering the questionnaire. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) q_text <- get_question_text("bdi.01") ## End(Not run)
Get the internal SQL field name (e.g. "697929X4X21") to a question from a specific survey in the dataset.
get_sql_varname(question_code, survey_id)
get_sql_varname(question_code, survey_id)
question_code |
Code by which to identify the question. Follows a dot-based naming scheme: <group title>.<subquestion title>. |
survey_id |
Survey-ID of the survey from which to select the question. |
'character' object containing the field name
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves name of the SQL table field in # which `LimeSurvey` internally stores the responses to this question. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) q_varname <- get_sql_varname("bdi.01", 123456) ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. # In this survey, a multiple-choice question identified by the code "bdi.01" # is used. # For this question, this example retrieves name of the SQL table field in # which `LimeSurvey` internally stores the responses to this question. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) q_varname <- get_sql_varname("bdi.01", 123456) ## End(Not run)
Get collected data from a specific survey on the connected 'LimeSurvey' instance. Includes complete and incomplete cases! Returns 'NULL' if no data has been collected in this survey.
get_survey_data(survey_id, completion_status = "all")
get_survey_data(survey_id, completion_status = "all")
survey_id |
ID of the survey from which the collected data shall be extracted. 6-digit integer. |
completion_status |
'complete' = Return only complete cases; 'incomplete' = Return only incomplete cases; 'all' = Return both. |
A 'data.frame' object containing the survey data. Column names follow a dot-based naming scheme: <group title>.<subquestion title>. 'NULL' if no data has been collected.
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) df_data <- get_survey_data(123456) ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) df_data <- get_survey_data(123456) ## End(Not run)
Get numerical LimeSurvey ID of the survey with the given title.
get_survey_id(survey_title)
get_survey_id(survey_title)
survey_title |
TItle of the survey. String. |
An integer Survey ID which can be used as a parameter in 'get_survey_data()'
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the title 'mysurvey'. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) survey_id <- get_survey_id('mysurvey') df_data <- get_survey_data(survey_id) ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the title 'mysurvey'. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) survey_id <- get_survey_id('mysurvey') df_data <- get_survey_data(survey_id) ## End(Not run)
Perform a call to the 'LimeSurvey' RPC API.
limesurvey_api_call(method, params = list(), ...)
limesurvey_api_call(method, params = list(), ...)
method |
Name of the API method to call. A complete list of methods can be found here: https://api.limesurvey.org/classes/remotecontrol_handle.html |
params |
Parameters to pass to the API |
... |
Additional parameters passed from above |
A list containing the de-serialized response.
Delete all data collected by this survey.
wipe_survey_data(survey_id)
wipe_survey_data(survey_id)
survey_id |
ID of the survey from which the collected data shall be deleted. 6-digit integer. |
Nothing. Function is called for side effects on SQL table.
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) wipe_survey_data(123456) ## End(Not run)
# This example assumes a locally hosted `LimeSurvey` instance using a locally # hosted MySQL server. # On this `LimeSurvey` instance, there is a survey with the ID 123456. ## Not run: connect_to_limesurvey( api_url = 'https://localhost/index.php/admin/remotecontrol', limesurvey_username = 'admin', limesurvey_password = '1234admin', mysql_host = '127.0.0.1', mysql_port = 3306, mysql_dbname = 'limesurvey', mysql_username = 'lime', mysql_password = '1234lime' ) wipe_survey_data(123456) ## End(Not run)