R/Rf_ScalarInteger.R

#' Rf_ScalarInteger
#'
#' @description
#'
#' \Sexpr[results=rd, stage=render]{c3po:::badge('fnp')} \Sexpr[results=rd, stage=render]{c3po:::badge('c2r')} \Sexpr[results=rd, stage=render]{c3po:::badge('prot')}
#'
#' Converts an \code{int x} to a [SEXP] object that represents an \R length one
#' \code{integer} vector.
#'
#' @section Declaration:
#' ```
#' SEXP Rf_ScalarInteger(int x);
#' ```
#' In [Rinternals.h](https://github.com/wch/r-source/blob/trunk/src/include/Rinternals.h).
#'
#' @section Definition:
#' ```
#' INLINE_FUN SEXP ScalarInteger(int x)
#' {
#'   SEXP ans = allocVector(INTSXP, 1);
#'   SET_SCALAR_IVAL(ans, x);
#'   return ans;
#' }
#' ```
#' In [Rinlinedfuns.h](https://github.com/wch/r-source/blob/trunk/src/include/Rinlinedfuns.h).
#'
#' @param x an int value.
#'
#' @return A [SEXP] object, namely a length one \code{integer} vector.
#'
#' @examples
#' # Convert a C int number as an R length one integer vector
#' forty_two <- inline::cfunction(NULL,
#'  ' int x = 42;
#'    SEXP y;
#'    y = PROTECT(Rf_ScalarInteger(x));
#'    UNPROTECT(1);
#'    return y;
#'  ')
#' forty_two()
#'
#'
#' @name Rf_ScalarInteger
#' @aliases ScalarInteger
#'
NULL
ramiromagno/c3po documentation built on Jan. 5, 2021, 8:01 p.m.