Skip to contents

Adds or updates survey metadata within a Project object stored in S3. The function automatically reads the current project version from S3, attaches or updates a survey entry, and writes the updated object back. Each wave holds at most one survey: attaching to a wave that already holds one replaces that entry.

Usage

dl_project_attach_survey(
  external_id = NA_character_,
  wave = NA_character_,
  type = "forsta",
  data = NULL,
  project = dl_get_project(),
  env = "prod"
)

Arguments

external_id

Character. External survey identifier (e.g., Forsta or Qualtrics ID). Required for "forsta" and "qualtrics" types.

wave

Character. Optional survey wave label. Defaults to NA_character_. Waves are unique within a project: attaching to a wave that already holds a survey replaces that entry. Use dl_project_detach_survey() to remove an entry.

type

Character. Survey type — one of "forsta", "qualtrics", or "direct". Defaults to "forsta". If "direct", data must be provided. When type is not given and data is provided without external_id, the type switches to "direct" automatically.

data

Optional data frame containing survey responses. For "direct" surveys, this is required and stored directly. For "forsta" and "qualtrics", data may be provided, overriding live download.

project

Character. Project ID to load from S3. Defaults to dl_get_project(). Must refer to an existing project initialized with dl_project_init().

env

Datalake environment ("prod" or "test"). Default "prod".

Value

The updated Project object (invisibly).

Details

If the project does not exist in S3, an error is raised instructing the user to initialize it first with dl_project_init(). If no changes are detected, the function confirms that the project is already in sync.

Examples

if (FALSE) { # \dontrun{
dl_project_attach_survey("selfserve/57a/251000")
dl_project_attach_survey("selfserve/57a/251001", wave = "w1")
dl_project_attach_survey("selfserve/57a/251001", wave = "w2", project = "genie")
} # }