R/vec_to_chunk.R

Defines functions vec_to_chunk

Documented in vec_to_chunk

#' Variable vector into chunks.
#'
#' \code{vec_to_chunk} takes a list of variables and collects them into 50-variable chunks.
#' 
#' This function takes a list of variable names and collects them into chunks with no more than 
#' 50 variables each. This helps to get around requests with more than 50 variables,because the 
#' API only allows queries of 50 variables at a time. 
#' The user should not need to call this function directly.
#'
#' @param x Character vector of variable names.
#' @return Object of class \code{list}.
#'
#' @examples
#' \dontrun{
#' vec_to_chunk(x = c(paste("P012F0", seq(10:49), sep = ""),
#'               paste("P012I0", seq(10, 49), sep = "")))
#' }
#'
#' @references
#' Based on code authored by Nicholas Nagle, which is available 
#' \href{https://rstudio-pubs-static.s3.amazonaws.com/19337_2e7f827190514c569ea136db788ce850.html}{here}.
#'
#' @keywords internal

vec_to_chunk <- function(x){
  s <- seq_along(x)
  x1 <- split(x, ceiling(s/50))
  return(x1)
}

Try the wru package in your browser

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

wru documentation built on Oct. 22, 2022, 1:05 a.m.