R/validate_survey.R

Defines functions validate_survey

#' Validate survey constructor arguments
#'
#' Check the data frame and survey-level metadata supplied
#' to the legacy survey constructor.
#'
#' @param object A data frame.
#' @param id A character scalar or NULL.
#' @param filename A character scalar or NULL.
#' @param doi A character scalar or NULL.
#'
#' @return Invisibly returns TRUE if validation succeeds.
#' @keywords internal
#' @noRd
validate_survey <- function(object, id, filename, doi) {
  if (!is.null(doi)) {
    if (!is.character(doi) || length(doi) != 1L) {
      stop(
        "The 'doi' must be a character of length 1L (or NULL)",
        call. = FALSE
      )
    }
  }

  if (!is.null(filename)) {
    if (!is.character(filename) || length(filename) != 1L) {
      stop(
        "The 'filename' must be a character of length 1L (or NULL)",
        call. = FALSE
      )
    }
  }

  if (!is.null(id)) {
    if (!is.character(id) || length(id) != 1L) {
      stop(
        "The 'id' must be a character of length 1L (or NULL)",
        call. = FALSE
      )
    }
  }

  if (!is.data.frame(object)) {
    stop(
      "df in validate_survey(df) must be a data.frame like object.",
      call. = FALSE
    )
  }

  invisible(TRUE)
}

Try the retroharmonize package in your browser

Any scripts or data that you put into this service are public.

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.