Closed junjunlab closed 1 year ago
Hi! It is hard to diagnose the problem based on what you wrote. Can you share the full example with us? E.g. the sequence of commands you executed.
Problem has been solved, thanks! By the way, how can I change rust hashmap into R list object with extendr, the following is my example incorrect code:
#[extendr]
fn get_hashmap() -> HashMap<String, f64> {
let mut map = HashMap::new();
map.insert("a".to_string(), 1.0);
map.insert("b".to_string(), 2.0);
map.insert("c".to_string(), 3.0);
map
}
It would be nice if you could still explain what was the original problem before we close the issue so in the future other developers can check it out before opening a new discussion.
Here is how to accomplish turning a hashmap into a list.
rust_function(
'
fn get_hashmap() -> List {
let mut map = std::collections::HashMap::new();
map.insert("a".to_string(), r!(1.0));
map.insert("b".to_string(), r!(2.0));
map.insert("c".to_string(), r!(3.0));
List::from_hashmap(map).unwrap()
}
'
)
There are two interesting point here.
Robj
s and cannot be Rfloat
for example. The following will not compile.
fn get_hashmap() -> List {
let mut map = std::collections::HashMap::new();
map.insert("a".to_string(), Rfloat::from(1.0));
map.insert("b".to_string(), Rfloat::from(2.0));
map.insert("c".to_string(), Rfloat::from(3.0));
List::from_hashmap(map).unwrap()
}
Well, hashmaps do not preserve the order of the items. In fact, hashmaps can return items in a different order every time you re-start the application, so that is expected. Speaking of requirement to store Robj
there, we need to check our trait bounds, I suspect you should be able to store any T : IntoRobj
there.
Hi! It is hard to diagnose the problem based on what you wrote. Can you share the full example with us? E.g. the sequence of commands you executed.
I'm also a new user, and I just simply followed the tutorial and very simply ran the following:
library(rextendr)
rextendr::use_extendr()
rextendr::document()
hello_world()
Everything printed in the R terminal before running hello_world()
seemed normal, but running the function outputs the following error: Error in hello_world() : object 'wrap__hello_world' not found
Can you try the following? I think you may need to load_all()
rextendr::use_extendr()
rextendr::document()
devtools::load_all()
hello_world()
Can you try the following? I think you may need to
load_all()
rextendr::use_extendr() rextendr::document() devtools::load_all() hello_world()
ah, worked perfectly, thank you!
First, rextendr::use_extendr()
is to be used only once per package.
My experience rexendr::document()
is all you need, but maybe I'm misunderstanding something.
Since everything is solved and everyone is happy, I'll close this.
Hi, I am creating an R package with example according to rextendr. But I got this error "Error in myextendr::hello_world() : object 'wrap__hello_world' not found" at last. How can I solve this error. Thanks!