cpp_source(
code = '#include "cpp11/integers.hpp"
[[cpp11::register]]
int num_odd(cpp11::integers x) {
int total = 0;
for (int val : x) {
if ((val % 2) == 1) {
++total;
}
}
return total;
}
')
num_odd(as.integer(c(1:10, 15, 23)))
if (interactive() && require("progress")) {
cpp_source(
code = '
#include
#include
[[cpp11::linking_to("progress")]]
[[cpp11::register]] void
show_progress() {
RProgress::RProgress pb("Processing [:bar] ETA: :eta");
pb.tick(0);
for (int i = 0; i < 100; i++) {
usleep(2.0 / 100 * 1000000);
pb.tick();
}
}
')
show_progress()
}
Run the code above in your browser using DataLab