https://github.com/nfultz/rcppjson
json for Rcpp
https://github.com/nfultz/rcppjson
json r rcpp
Last synced: about 1 year ago
JSON representation
json for Rcpp
- Host: GitHub
- URL: https://github.com/nfultz/rcppjson
- Owner: nfultz
- Created: 2018-10-11T18:21:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T21:52:21.000Z (over 7 years ago)
- Last Synced: 2025-04-05T03:41:24.301Z (about 1 year ago)
- Topics: json, r, rcpp
- Language: C++
- Size: 109 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RcppJson
This provides Niels Lohmann's excellent [json library](https://github.com/nlohmann/json) 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
// 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"];
}
')
```