Skip to content

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

Closed
@vspinu

Description

@vspinu
#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions