Skip to content

Commit 825d721

Browse files
committed
Use lobstr inspect
1 parent 7462ddd commit 825d721

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

crates/ark/src/debug.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::ffi;
22
use std::sync::atomic::Ordering;
33

4+
use harp::exec::RFunction;
5+
use harp::exec::RFunctionExt;
46
use harp::utils::r_str_to_owned_utf8_unchecked;
57

68
use crate::interface::RMain;
@@ -15,10 +17,21 @@ pub extern "C" fn ark_print_rs(x: libr::SEXP) -> *const ffi::c_char {
1517
})
1618
}
1719

20+
// Uses lobstr's `sxp()` function because libr can't find `R_inspect()`.
21+
// It's an `attribute_hidden` function but since the symbol is visible
22+
// on macOS (and you can call it in the debugger) I would have expected
23+
// libr to be able to find it.
1824
#[no_mangle]
1925
pub extern "C" fn ark_inspect_rs(x: libr::SEXP) -> *const ffi::c_char {
2026
capture_console_output(|| {
21-
unsafe { libr::R_inspect(x) };
27+
// FIXME: These options don't seem to work
28+
let one = harp::RObject::try_from(1).unwrap();
29+
harp::raii::RLocalOption::new("cli.num_colors", one.sexp);
30+
31+
harp::raii::RLocalOptionBoolean::new("cli.unicode", false);
32+
33+
let out = RFunction::new("lobstr", "sxp").add(x).call().unwrap();
34+
unsafe { libr::Rf_PrintValue(out.sexp) };
2235
})
2336
}
2437

crates/libr/src/r.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ functions::generate! {
317317

318318
pub fn Rf_PrintValue(x: SEXP);
319319

320-
pub fn R_inspect(x: SEXP) -> SEXP;
321-
322320
pub fn R_PromiseExpr(p: SEXP) -> SEXP;
323321

324322
pub fn R_BytecodeExpr(e: SEXP) -> SEXP;

0 commit comments

Comments
 (0)