Skip to content
Back to skills

Cpp11

ASecurity

R cpp11 package for C++ integration. Use for modern C++11 integration with R.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 4, 2026
datac++awsapi

Works with

  • api

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill cpp11 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cpp11?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cpp11
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-cpp11/badge)](https://www.skillsdirectory.com/skills/leolin990405-cpp11)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cpp11
description: R cpp11 package for C++ integration. Use for modern C++11 integration with R.
---

# cpp11

A header-only C++11 interface for R.

## Basic Function

```cpp
// myfile.cpp
#include "cpp11.hpp"
using namespace cpp11;

[[cpp11::register]]
double sum_cpp(doubles x) {
  double total = 0;
  for (double val : x) {
    total += val;
  }
  return total;
}
```

```r
cpp11::cpp_source("myfile.cpp")
sum_cpp(1:10)
```

## Vector Types

```cpp
// Read-only vectors
doubles x;      // NumericVector
integers i;     // IntegerVector
strings s;      // CharacterVector
logicals l;     // LogicalVector
raws r;         // RawVector
list lst;       // List

// Writable vectors
writable::doubles x;
writable::integers i;
writable::strings s;
writable::logicals l;
```

## Creating Vectors

```cpp
[[cpp11::register]]
doubles create_vec() {
  writable::doubles x(10);
  for (int i = 0; i < 10; i++) {
    x[i] = i * 2.0;
  }
  return x;
}
```

## Named Vectors

```cpp
[[cpp11::register]]
doubles named_vec() {
  using namespace cpp11::literals;
  writable::doubles x({"a"_nm = 1.0, "b"_nm = 2.0});
  return x;
}
```

## Lists

```cpp
[[cpp11::register]]
list return_list(doubles x) {
  using namespace cpp11::literals;
  writable::list result;
  result.push_back({"mean"_nm = mean(x)});
  result.push_back({"data"_nm = x});
  return result;
}
```

## Data Frames

```cpp
[[cpp11::register]]
data_frame create_df() {
  using namespace cpp11::literals;
  writable::doubles x = {1.0, 2.0, 3.0};
  writable::strings y = {"a", "b", "c"};
  return writable::data_frame({
    "x"_nm = x,
    "y"_nm = y
  });
}
```

## Matrices

```cpp
[[cpp11::register]]
doubles_matrix<> mat_ops(doubles_matrix<> m) {
  int nrow = m.nrow();
  int ncol = m.ncol();

  writable::doubles_matrix<> result(nrow, ncol);
  for (int i = 0; i < nrow; i++) {
    for (int j = 0; j < ncol; j++) {
      result(i, j) = m(i, j) * 2;
    }
  }
  return result;
}
```

## Attributes

```cpp
[[cpp11::register]]
doubles with_attrs(doubles x) {
  writable::doubles y(x);
  y.attr("class") = "myclass";
  return y;
}
```

## Package Integration

```r
# In package DESCRIPTION
LinkingTo: cpp11

# In R/
#' @useDynLib mypackage, .registration = TRUE
NULL
```

## Comparison with Rcpp

```cpp
// cpp11 advantages:
// - Header-only (no compilation of Rcpp)
// - Modern C++11 features
// - ALTREP support
// - Stricter type safety
// - No R API macros
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.