Skip to content
R-friendly threading in C++
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
docs
inst
man
tests
vignettes
.Rbuildignore
.gitignore
.travis.yml
DESCRIPTION
Doxyfile.in
LICENSE
LICENSE.md
NAMESPACE
NEWS.md
README.md
RcppThread.Rproj
appveyor.yml
cran-comments.md

README.md

RcppThread

Travis-CI Build Status AppVeyor Build Status CRAN version CRAN downloads

Provides R-friendly threading functionality:

  • thread safe versions of Rcpp's checkUserInterrupt() and Rcout,
  • an interruptible thread class that otherwise behaves like std::thread,
  • classes for the thread pool pattern and parallel for loops for easy and flexible parallelism.

The library is header-only, platform-independent, and only requires a C++11-compatible compiler.

Functionality

For a detailed description of its functionality and examples, see the vignette or the API documentation.

Installation

Release version from CRAN:

install.packages("RcppThread")

Latest development version from github:

# install.packages("devtools")
devtools::install_github("tnagler/RcppThread")

How to use it

with cppFunction

Pass "RcppThread" to the depends argument and "cpp11" to the plugins argument. For example:

Rcpp::cppFunction('void func() { /* actual code here */ }', 
                       depends = "RcppThread", plugins = "cpp11")
with sourceCpp

Add

// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(RcppThread)]]

before including any headers in your source code.

in another R package
  1. Add the line CXX_STD = CXX11 to the src/Makevars(.win) files of your package.
  2. Add RcppThread to the LinkingTo field of your DESCRIPTION file.

Automatic override of std::cout and std::thread

There are preprocessor options to replace all occurences of std::cout and std::thread with calls to RcppThread::Rcout and RcppThread::Thread (provided that the RcppThread headers are included first). To enable this, use

#define RCPPTHREAD_OVERRIDE_COUT 1    // std::cout override
#define RCPPTHREAD_OVERRIDE_THREAD 1  // std::thread override

before including the RcppThread headers.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.