Skip to content

R dies on scalar/vector mismatch #375

@johnlaing

Description

@johnlaing

If I declare a function taking a scalar and call it with a vector, R dies. Ideally Rcpp would check the length of the input and throw.

I understand this is likely a non-trivial fix. Nevertheless...

Rcpp::sourceCpp(code='
#include <Rcpp.h>
// [[Rcpp::export]]

std::string ex(std::string x) {
  std::string y = x;
  return(y);
}
')

ex("foo") ## it works if I pass it a scalar
# [1] "foo"

ex(c("foo", "bar")) ## but explodes on a vector
# *** Error in `/usr/lib/R/bin/exec/R': free(): invalid pointer: 0x0000000002d15418 ***
# Aborted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions