-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear error when r_string
is used as an argument
#311
Comments
hi,I met a problem in laerning R ,can you give me some help? thank you very much if you can lend me some time! |
I don't know if you did, but I would try https://www.stackoverflow.com to post problems like this. |
thank you for your help. Finally i got the solution –—— n <- sum(c(1.1,2.2,3.5))
use c(...) to pass vector of numbers
…---- Replied Message ----
| From | ***@***.***> |
| Date | 04/15/2023 07:27 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [r-lib/cpp11] Unclear error when `r_string` is used as an argument (Issue #311) |
hi,I met a problem in laerning R ,can you give me some help? My question link is : How to pass parameters in .R file to cpp11 function in .cpp file
thank you very much if you can lend me some time!
I don't know if you did, but I would try https://www.stackoverflow.com to post problems like this.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
I think we want the FWIW we do allow conversion directly into a cpp11::cpp_source(code='
#include <string>
#include "cpp11.hpp"
[[cpp11::register]]
cpp11::writable::strings foo(std::string bar) {
cpp11::writable::strings out = { bar };
return out;
}'
)
foo("hello")
#> [1] "hello" Note to self that this occurs because we have cpp11/inst/include/cpp11/as.hpp Lines 33 to 37 in b0576f2
Used in cpp11/inst/include/cpp11/as.hpp Lines 81 to 84 in b0576f2
And cpp11/inst/include/cpp11/r_string.hpp Line 17 in b0576f2
It's possible we could add a more specific |
Thanks. I think I had an unusual use-case; most of the time casting to FWIW - I'd be surprised if there was a substantial performance hit; between inlining, branch prediction, and the simple pointer access via TYPEOF, most CPUs will cruise through it ... but I am willing to be corrected if anyone did some profiling. Thanks again for looking into this. |
I know why this doesn't work; however it took a while to track down (and I didn't find help elsewhere) - so at least if I put this here it might help others.
Basic idea is what if you want to pass a 'scalar' character vector (i.e. invoke a function in R like
foo("test")
), it looks like the pattern I have to use is:No problems.
On the other hand, trying this (and hoping that cpp11 does the hard work) fails:
As a suggestion, perhaps have a valid_type check on the data similar to
r_vector
; e.g.The text was updated successfully, but these errors were encountered: