Skip to content

Commit 74f5f7a

Browse files
committed
Export global references to Ark namespaces
1 parent 17efccc commit 74f5f7a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

crates/ark/src/modules.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use anyhow::anyhow;
99
use harp::environment::Environment;
1010
use harp::environment::R_ENVS;
11+
use harp::eval::r_parse_eval;
1112
use harp::exec::r_parse_exprs_with_srcrefs;
1213
use harp::exec::r_source_str_in;
1314
use harp::exec::RFunction;
@@ -18,6 +19,7 @@ use libr::R_NilValue;
1819
use libr::Rf_ScalarLogical;
1920
use libr::Rf_asInteger;
2021
use libr::SEXP;
22+
use once_cell::sync::Lazy;
2123
use rust_embed::RustEmbed;
2224

2325
#[derive(RustEmbed)]
@@ -46,6 +48,37 @@ where
4648
f(data)
4749
}
4850

51+
pub static ARK_ENVS: Lazy<ArkEnvs> = Lazy::new(|| {
52+
let positron_ns = r_parse_eval(
53+
"environment(as.environment('tools:positron')$.ps.internal)",
54+
Default::default(),
55+
)
56+
.unwrap()
57+
.sexp;
58+
59+
let rstudio_ns = r_parse_eval(
60+
"as.environment('tools:rstudio')$.__rstudio_ns__.",
61+
Default::default(),
62+
)
63+
.unwrap()
64+
.sexp;
65+
66+
ArkEnvs {
67+
positron_ns,
68+
rstudio_ns,
69+
}
70+
});
71+
72+
// Silences diagnostics when called from `r_task()`. Should only be
73+
// accessed from the R thread.
74+
unsafe impl Send for ArkEnvs {}
75+
unsafe impl Sync for ArkEnvs {}
76+
77+
pub struct ArkEnvs {
78+
pub positron_ns: SEXP,
79+
pub rstudio_ns: SEXP,
80+
}
81+
4982
pub fn initialize(testing: bool) -> anyhow::Result<()> {
5083
// If we are `testing`, set the corresponding R level global option
5184
if testing {

0 commit comments

Comments
 (0)