Allocates a Vector

allocVector(type, length)

Source

Declaration: src/include/Rinternals.h and src/include/Rdefines.h

Implementation: allocVector(SEXPTYPE type, R_xlen_t length) is a simple inline wrapper functions that calls allocVector3(type, length, NULL), cf. src/include/Rinlinedfuns.h

Arguments

type

(SEXPTYPE) An macro constant of length one.

length

(R_xlen_t) An non-negative integer.

Value

allocVector() returns an SEXP object of type SEXPTYPE

type.

C API

#include <Rinternals.h>
SEXP     Rf_allocVector(SEXPTYPE, R_xlen_t)
#define allocVector     Rf_allocVector

Related macros:

#include <Rdefines.h>
#define NEW_LOGICAL(n)      Rf_allocVector(LGLSXP,n)
#define NEW_INTEGER(n)      Rf_allocVector(INTSXP,n)
#define NEW_NUMERIC(n)      Rf_allocVector(REALSXP,n)
#define NEW_CHARACTER(n)    Rf_allocVector(STRSXP,n)
#define NEW_COMPLEX(n)      Rf_allocVector(CPLXSXP,n)
#define NEW_LIST(n)     Rf_allocVector(VECSXP,n)
#define NEW_STRING(n)       NEW_CHARACTER(n)
#define NEW_RAW(n)      Rf_allocVector(RAWSXP,n)

R API

library(base)

x_logical   <- logical(length = n)
x_integer   <- integer(length = n)
x_numeric   <- numeric(length = n)
x_character <- character(length = n)
x_complex   <- complex(length.out = n)
x_list      <- vector(mode = "list", length = n)
x_raw       <- raw(length = n)