diff --git a/crates/ark/src/variables/variable.rs b/crates/ark/src/variables/variable.rs index ab701a034..84d7c9e5a 100644 --- a/crates/ark/src/variables/variable.rs +++ b/crates/ark/src/variables/variable.rs @@ -1864,7 +1864,8 @@ mod tests { fn inspect_from_expr(code: &str) -> Vec { let env = Environment::new(harp::parse_eval_base("new.env(parent = emptyenv())").unwrap()); - env.bind("x".into(), harp::parse_eval_base(code).unwrap()); + let value = harp::parse_eval_base(code).unwrap(); + env.bind("x".into(), &value); // Inspect the S4 object let path = vec![String::from("x")]; PositronVariable::inspect(env.into(), &path).unwrap() @@ -1971,10 +1972,8 @@ mod tests { fn test_truncation_on_matrices() { r_task(|| { let env = Environment::new_empty().unwrap(); - env.bind( - "x".into(), - harp::parse_eval_base("matrix(0, nrow = 10000, ncol = 10000)").unwrap(), - ); + let value = harp::parse_eval_base("matrix(0, nrow = 10000, ncol = 10000)").unwrap(); + env.bind("x".into(), &value); // Inspect the matrix, we should see the list of columns truncated let path = vec![String::from("x")]; @@ -1993,10 +1992,8 @@ mod tests { fn test_string_truncation() { r_task(|| { let env = Environment::new_empty().unwrap(); - env.bind( - "x".into(), - harp::parse_eval_base("paste(1:5e6, collapse = ' - ')").unwrap(), - ); + let value = harp::parse_eval_base("paste(1:5e6, collapse = ' - ')").unwrap(); + env.bind("x".into(), &value); let path = vec![]; let vars = PositronVariable::inspect(env.into(), &path).unwrap(); @@ -2006,7 +2003,8 @@ mod tests { // Test for the empty string let env = Environment::new_empty().unwrap(); - env.bind("x".into(), harp::parse_eval_base("''").unwrap()); + let value = harp::parse_eval_base("''").unwrap(); + env.bind("x".into(), &value); let path = vec![]; let vars = PositronVariable::inspect(env.into(), &path).unwrap(); @@ -2015,10 +2013,8 @@ mod tests { // Test for the single elment matrix, but with a large character let env = Environment::new_empty().unwrap(); - env.bind( - "x".into(), - harp::parse_eval_base("matrix(paste(1:5e6, collapse = ' - '))").unwrap(), - ); + let value = harp::parse_eval_base("matrix(paste(1:5e6, collapse = ' - '))").unwrap(); + env.bind("x".into(), &value); let path = vec![]; let vars = PositronVariable::inspect(env.into(), &path).unwrap(); assert_eq!(vars.len(), 1); @@ -2027,10 +2023,8 @@ mod tests { // Test for the empty matrix let env = Environment::new_empty().unwrap(); - env.bind( - "x".into(), - harp::parse_eval_base("matrix(NA, ncol = 0, nrow = 0)").unwrap(), - ); + let value = harp::parse_eval_base("matrix(NA, ncol = 0, nrow = 0)").unwrap(); + env.bind("x".into(), &value); let path = vec![]; let vars = PositronVariable::inspect(env.into(), &path).unwrap(); assert_eq!(vars.len(), 1); diff --git a/crates/harp/src/environment.rs b/crates/harp/src/environment.rs index 9d296a774..238a5f507 100644 --- a/crates/harp/src/environment.rs +++ b/crates/harp/src/environment.rs @@ -91,13 +91,13 @@ impl Environment { std::iter::successors(Some(self.clone()), |p| p.parent()) } - pub fn bind(&self, name: RSymbol, value: impl Into) { + pub fn bind(&self, name: RSymbol, value: &RObject) { unsafe { - Rf_defineVar(name.sexp, value.into(), self.inner.sexp); + Rf_defineVar(name.sexp, value.sexp, self.inner.sexp); } } - pub fn force_bind(&self, name: RSymbol, value: impl Into) { + pub fn force_bind(&self, name: RSymbol, value: &RObject) { let locked = self.is_locked_binding(name); if locked { self.unlock_binding(name); diff --git a/crates/harp/src/utils.rs b/crates/harp/src/utils.rs index 141cf0a9e..cd0e00f87 100644 --- a/crates/harp/src/utils.rs +++ b/crates/harp/src/utils.rs @@ -673,8 +673,9 @@ pub fn save_rds(x: SEXP, path: &str) { let path = RObject::from(path); let env = Environment::new(harp::parse_eval_base("new.env()").unwrap()); - env.bind("x".into(), x); - env.bind("path".into(), path); + let x = RObject::from(x); + env.bind("x".into(), &x); + env.bind("path".into(), &path); let res = harp::parse_eval0("base::saveRDS(x, path)", env); @@ -701,9 +702,10 @@ pub fn push_rds(x: SEXP, path: &str, context: &str) { let env = Environment::new(harp::parse_eval_base("new.env()").unwrap()); - env.bind("x".into(), x); - env.bind("path".into(), path); - env.bind("context".into(), context); + let x = RObject::from(x); + env.bind("x".into(), &x); + env.bind("path".into(), &path); + env.bind("context".into(), &context); let res = harp::parse_eval0(".ps.internal(push_rds(x, path, context))", env);