nettskjema_get_data: Get data from a form

View source: R/nettskjema_get_form.R

nettskjema_get_dataR Documentation

Get data from a form

Description

This function connects to a specific form and fetches all answers. The responses are placed in a data.frame for easy use. For large data sets, toggle the incremental option, which while slow, will be better able to retrieve all responses. For retrieving responses only from a specific date on, or all responses after a certain submission, use the from_date and from_submission arguments. Forms that are anonymous and do not collect personal information do not record date, and as such the from_date will not work on those and an error will be thrown.

Usage

nettskjema_get_data(
  form_id,
  information = NULL,
  token_name = "NETTSKJEMA_API_TOKEN",
  use_codebook = has_codebook(form_id, token_name),
  checkbox_type = c("string", "list", "columns"),
  checkbox_delim = ";",
  as_is = FALSE,
  from_date = "",
  from_submission = "",
  incremental = FALSE,
  ...
)

Arguments

form_id

integer. Number of the form to retrieve

information

character or list vector of additional answer information to add (One or more of "order", "option", "correct" "preselected"). If the list is named, the additional information suffixes will be changed to the list names. If NULL (default) nothing is added. Currently not possible to combine with use_codebook = TRUE.

token_name

character. Name to give the token, defaults to 'NETTSKJEMA_API_TOKEN'

use_codebook

logical. Use codebook for retrieving answers (default TRUE). If you have not set up the codebook in nettskjema, then turning this off will return the data as is.

checkbox_type

string of either "string" (default), "list" or "columns" for how to handle checkbox answers

checkbox_delim

delimiter string if checkbox:type is "string". Ignored else.

as_is

logical. Whether to return the raw content from nettskjema. Default is FALSE.

from_date

date. From which date on should data be fetched for

from_submission

integer. From which SubmissionId should data be collected from.

incremental

logical. False fetches all at once, TRUE fetches each submission individually. Slower but more stable for larger datasets.

...

arguments passed to GET

Details

Checkbox types

  • "string" - returns a delimited character value per submission, where checkbox_delim denotes the options that the respondent has chosen

  • "list" - returns a list column, where each submission has a character vector with all the chosen options as separate elements in the list

  • "columns" - returns checkbox answers as separate binarized columns (column names are appended with response names), where 1 means the option was selected and 0 it was not.

Value

tibble data.frame

Examples

## Not run: 

# Retrieve all data
data_110000 <- nettskjema_get_data(110000)
# Retrieve all data, and add answer order and option text
data_110000 <- nettskjema_get_data(110000, information = list(dummy = "order", text = "option"))

# Retrieve all data after a certain date
data_110000 <- nettskjema_get_data(110000, from_date = "2019-01-01")

# Retrieve all submissions after a specific submission id
data_110000 <- nettskjema_get_data(110000, from_submission = "12000000")

# For large data
data_110000 <- nettskjema_get_data(110000, incremental = TRUE)


## End(Not run)

LCBC-UiO/nettskjemar documentation built on Aug. 24, 2023, 5:44 p.m.