File: RConverter.h

package info (click to toggle)
r-cran-sourcetools 0.1.7-1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 308 kB
  • sloc: cpp: 1,985; ansic: 505; sh: 10; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef SOURCETOOLS_R_R_CONVERTER_H
#define SOURCETOOLS_R_R_CONVERTER_H

#include <vector>
#include <string>

#include <sourcetools/r/RUtils.h>
#include <sourcetools/r/RHeaders.h>

namespace sourcetools {
namespace r {

inline SEXP Rf_mkChar(const std::string& data)
{
  return Rf_mkCharLen(data.c_str(), data.size());
}

inline SEXP Rf_mkString(const std::string& data)
{
  Protect protect;
  SEXP resultSEXP = protect(Rf_allocVector(STRSXP, 1));
  SET_STRING_ELT(resultSEXP, 0, Rf_mkChar(data));
  return resultSEXP;
}

inline SEXP create(const std::vector<std::string>& vector)
{
  Protect protect;
  std::size_t n = vector.size();
  SEXP resultSEXP = protect(Rf_allocVector(STRSXP, n));
  for (std::size_t i = 0; i < n; ++i)
    SET_STRING_ELT(resultSEXP, i, Rf_mkChar(vector[i]));
  return resultSEXP;
}

} // namespace r
} // namespace sourcetools

#endif /* SOURCETOOLS_R_R_CONVERTER_H */