Can't access an Rcpp class when installing package

Hi!
I am building an R package with some C++ code, but I am doing something wrong and can't access the C++ class from R. I made a simple example (full code here: https://github.com/sellisd/rcppexample) to understand the problem. I have a single C++ class:

#include <Rcpp.h>
using namespace Rcpp;

class MyClass
{
public:
  std::string text;
  char character;
  MyClass(std::string a = "Hello", char b = 'W')
  {
    text = a;
    character = b;
  }
private:
  int donothing = 3;
};

RCPP_EXPOSED_CLASS(MyClass);

RCPP_MODULE(MyClass){
  class_<MyClass>("MyClass")
  .constructor<std::string, char>()
  .field("text", &MyClass::text)
  .field("character", &MyClass::character)
  ;
};

and a R/rcppexample-package.R where I pasted the output from usethis::use_rcpp():

## usethis namespace: start
#' @useDynLib rcppexample, .registration = TRUE
## usethis namespace: end
NULL
## usethis namespace: start
#' @importFrom Rcpp sourceCpp
## usethis namespace: end
NULL

I am building in rstudio with Ctrl+Shift+B ( R CMD INSTALL --no-multiarch --with-keep.source rcppexample) and when loading the library I cannot access MyClass:

> library(rcppexample)
> MyClass
Error: object 'MyClass' not found

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.