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

attributes ignored on non-writable objects during explicit set or construction #237

Closed
vspinu opened this issue Aug 19, 2021 · 4 comments
Closed

Comments

@vspinu
Copy link
Contributor

vspinu commented Aug 19, 2021

#include "cpp11.hpp"
using namespace cpp11::literals;


[[cpp11::register]]
cpp11::data_frame test_wrong() {
  cpp11::doubles time({123456});
  time.attr("class") = cpp11::strings({"POSIXct", "POSIXt"});
  time.attr("tzone") = cpp11::strings({"UTC"});
  return cpp11::data_frame({
	  "time"_nm = time
	});
}
 
[[cpp11::register]]
cpp11::data_frame test_right() {
  cpp11::writable::doubles time({123456});
  time.attr("class") = cpp11::strings({"POSIXct", "POSIXt"});
  time.attr("tzone") = cpp11::strings({"UTC"});
  return cpp11::writable::data_frame({
	  "time"_nm = time
	});
}


> str(test_wrong())
List of 1
 $ time: num 123456
> str(test_right())
'data.frame':	1 obs. of  1 variable:
 $ time: POSIXct, format: "1970-01-02 10:17:36"

Issues:

  1. setting attributes on non-writable objects has no effect but does not trigger compile or run-time errors
  2. initialization list cpp11::data_frame constructor produces a list instead of a data frame
@jimhester
Copy link
Member

jimhester commented Sep 16, 2021

Thanks for opening the issue with reproducible examples! They are a large help.

Fixed by 547a494 and 7312b66

@vspinu
Copy link
Contributor Author

vspinu commented Oct 29, 2021

@jimhester 7312b66 actually broke my second example, which I believe is valid.

#include "cpp11.hpp"
using namespace cpp11::literals;

 
[[cpp11::register]]
cpp11::data_frame test_right() {
  cpp11::writable::doubles time({123456});
  time.attr("class") = cpp11::strings({"POSIXct", "POSIXt"});
  time.attr("tzone") = cpp11::strings({"UTC"});
  return cpp11::writable::data_frame({
	  "time"_nm = time
	});
}
/tmp/tmp.cpp:9:46: error: call of overloaded ‘r_vector(<brace-enclosed initializer list>)’ is ambiguous
   time.attr("tzone") = cpp11::strings({"UTC"});
                                              ^

@jimhester
Copy link
Member

In this case there is no need for the explicit cpp11::strings() constructor e.g.

cpp11::cpp_source(code = '#include <cpp11.hpp>
  using namespace cpp11::literals;
  [[cpp11::register]]
  cpp11::data_frame test_right() {
    cpp11::writable::doubles time({123456});
    time.attr("class") = {"POSIXct", "POSIXt"};
    time.attr("tzone") = {"UTC"};
    return cpp11::writable::data_frame({
      "time"_nm = time
    });
  }
  ')

test_right()
#>                  time
#> 1 1970-01-02 10:17:36

Created on 2021-10-29 by the reprex package (v2.0.1)

@vspinu
Copy link
Contributor Author

vspinu commented Oct 29, 2021

I see. Thanks!

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

No branches or pull requests

2 participants