Can't access an Rcpp class when installing package

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: to understand the problem. I have a single C++ class:

#include <Rcpp.h>
using namespace Rcpp;

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


  .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
## usethis namespace: start
#' @importFrom Rcpp sourceCpp
## usethis namespace: end

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.