Skip to content

nfultz/RcppJson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RcppJson

This provides Niels Lohmann's excellent json library for Rcpp. All credit goes to him.

Installation

remotes::install_github("nfultz/RcppJson")

It can also theoretically be used by a package by adding LinkingTo: RcppJson to your DESCRIPTION file

Motivating Example

This demonstrates creating a json directly, as well as parsing and dumping text.

sourceCpp(code='

// [[Rcpp::depends(RcppJson)]]
// [[Rcpp::plugins(cpp14)]]

#include <nlohmann/json.hpp>

// for convenience
using json = nlohmann::json;

// [[Rcpp::export]]
auto boxme(const int &x) {


  auto j2 = R"(
    {
              "happy": true,
              "pi": 3.141
              }
  )"_json;

  j2["x"] = x;


  return j2.dump();


}          


// [[Rcpp::export]]
int unboxme(std::string x) {


  json j2 = json::parse(x);

  return j2["x"];


}          


          
')

About

json for Rcpp

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages