Skip to content
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

writable::logicals::proxy = bool #56

Closed
romainfrancois opened this issue Jul 24, 2020 · 2 comments · Fixed by #57 or #105
Closed

writable::logicals::proxy = bool #56

romainfrancois opened this issue Jul 24, 2020 · 2 comments · Fixed by #57 or #105

Comments

@romainfrancois
Copy link
Collaborator

cpp11::cpp_function('
cpp11::writable::logicals bools(){ 
  cpp11::writable::logicals x(1);
  x[0] = true;
  return x;
  } 
', quiet = FALSE)
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/romainfrancois/.R/library/4.0/cpp11/include  -I/usr/local/include   -fPIC  -Wall -O3 -Wall -Wimplicit-int-float-conversion -c /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/Rtmp4AL6sg/file3d916be862b1/src/code_0.cpp -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/Rtmp4AL6sg/file3d916be862b1/src/code_0.o
#> /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/Rtmp4AL6sg/file3d916be862b1/src/code_0.cpp:8:8: error: no viable overloaded '='
#>   x[0] = true;
#>   ~~~~ ^ ~~~~
#> /Users/romainfrancois/.R/library/4.0/cpp11/include/cpp11/r_vector.hpp:216:9: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'bool' to 'const cpp11::writable::r_vector<Rboolean>::proxy' for 1st argument
#>   class proxy {
#>         ^
#> /Users/romainfrancois/.R/library/4.0/cpp11/include/cpp11/logicals.hpp:51:71: note: candidate function not viable: no known conversion from 'bool' to 'const Rboolean' for 1st argument
#> inline typename r_vector<Rboolean>::proxy& r_vector<Rboolean>::proxy::operator=(
#>                                                                       ^
#> 1 error generated.
#> make: *** [/private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/Rtmp4AL6sg/file3d916be862b1/src/code_0.o] Error 1
#> Error in dyn.load(shared_lib, local = TRUE, now = TRUE): unable to load shared object '/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T//Rtmp4AL6sg/file3d916be862b1/src/code_0.so':
#>   dlopen(/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T//Rtmp4AL6sg/file3d916be862b1/src/code_0.so, 6): image not found
bools()
#> Error in .Call("_code_0_bools", PACKAGE = "code_0"): "_code_0_bools" not available for .Call() for package "code_0"

Created on 2020-07-24 by the reprex package (v0.3.0.9001)

We can do this 👇, but I believe it still would be useful to allow it.

cpp11::cpp_function('
cpp11::writable::logicals bools(){ 
  cpp11::writable::logicals x(1);
  x[0] = true ? TRUE : FALSE;
  return x;
  } 
', quiet = FALSE)
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/romainfrancois/.R/library/4.0/cpp11/include  -I/usr/local/include   -fPIC  -Wall -O3 -Wall -Wimplicit-int-float-conversion -c /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/code_0.cpp -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/code_0.o
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/romainfrancois/.R/library/4.0/cpp11/include  -I/usr/local/include   -fPIC  -Wall -O3 -Wall -Wimplicit-int-float-conversion -c /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/cpp11.cpp -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/cpp11.o
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/code_0.so /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/code_0.o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpFsTE6w/file3dd0596b29c2/src/cpp11.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
bools()
#> [1] TRUE

Created on 2020-07-24 by the reprex package (v0.3.0.9001)

@bkietz
Copy link
Collaborator

bkietz commented Jul 29, 2020

@jimhester should we reopen this? One way to handle this would be to extract r_bool the way we do r_string. r_bool can be made constructible from/convertible to bool and Rboolean so that x[0] = true and x[1] = FALSE would both work

@jimhester jimhester reopened this Jul 29, 2020
@jimhester
Copy link
Member

Yeah that might be a good solution.

That could also allow us to avoid defining the Rboolean enumeration ourselves as well, which can cause issues if you include R headers which define it in the wrong order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants