in language-extensions/R/src/RTypeUtils.cpp [91:133]
RVectorType RTypeUtils::CreateVector(
SQLULEN rowsNumber,
SQLPOINTER data,
SQLINTEGER *strLen_or_Ind,
SQLSMALLINT nullable)
{
LOG("RTypeUtils::CreateVector");
// Note: Always preallocate the Rcpp vector with the size instead of using
// push_back since Rcpp push_back involves copying to create a new vector in R environment.
//
RVectorType vectorInR(rowsNumber);
bool isNullable = nullable == SQL_NULLABLE;
for (SQLULEN index = 0; index < rowsNumber; ++index)
{
if (isNullable &&
strLen_or_Ind != nullptr &&
strLen_or_Ind[index] == SQL_NULL_DATA)
{
// It is NULL (NA) only in this case.
//
NAType valueForNA = *(static_cast<NAType*>(sm_dataTypeToNAMap.at(DataType)));
vectorInR[index] = valueForNA;
}
else
{
// In all other scenarios, it is not NULL (NA).
//
SQLType value = static_cast<SQLType *>(data)[index];
if constexpr (DataType != SQL_C_BIT)
{
vectorInR[index] = value;
}
else
{
vectorInR[index] = value != '0' && value != 0;
}
}
}
return vectorInR;
}