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

Unable to write two tables in a RData file #38

Open
RudolphDev opened this issue Jan 7, 2021 · 3 comments
Open

Unable to write two tables in a RData file #38

RudolphDev opened this issue Jan 7, 2021 · 3 comments
Labels

Comments

@RudolphDev
Copy link

RudolphDev commented Jan 7, 2021

Hello,

I would use your library to write RData in a C++ software but i can't use it.
I try to write an RData from your example, everything works but when i want to add a second table the produced RData can't be loaded in R. I tried to load with R 3.5 and R 4.0 in the both cases R gave me the error : ReadItem : unknown type 0, perhaps written by later version of R ?

This is the script I use:

int fd = open("/data/test.RData", O_CREAT | O_WRONLY, 0644);
rdata_writer_t *mp_rdataWriter = rdata_writer_init(&write_data, RDATA_WORKSPACE);
int m_rowCount = 3;

rdata_column_t *col1 =
  rdata_add_column(mp_rdataWriter, "column1", RDATA_TYPE_REAL);
rdata_column_t *col2 =
  rdata_add_column(mp_rdataWriter, "column2", RDATA_TYPE_STRING);
rdata_column_t *col3 =
  rdata_add_column(mp_rdataWriter, "column3", RDATA_TYPE_REAL);
rdata_column_t *col4 =
  rdata_add_column(mp_rdataWriter, "column4", RDATA_TYPE_STRING);

rdata_begin_file(mp_rdataWriter, &fd);
rdata_begin_table(mp_rdataWriter, "my_table");


rdata_begin_column(mp_rdataWriter, col1, m_rowCount);
rdata_append_real_value(mp_rdataWriter, 0.0);
rdata_append_real_value(mp_rdataWriter, 100.0);
rdata_append_real_value(mp_rdataWriter, 200.0);
rdata_end_column(mp_rdataWriter, col1);


rdata_begin_column(mp_rdataWriter, col2, m_rowCount);
rdata_append_string_value(mp_rdataWriter, "hello");
rdata_append_string_value(mp_rdataWriter, "goodbye");
rdata_append_string_value(mp_rdataWriter, "test");
rdata_end_column(mp_rdataWriter, col2);

rdata_end_table(mp_rdataWriter, m_rowCount, "My data set");

rdata_begin_table(mp_rdataWriter, "test2");

rdata_begin_column(mp_rdataWriter, col3, 2);
rdata_append_real_value(mp_rdataWriter, 0.0);
rdata_append_real_value(mp_rdataWriter, 100.0);
rdata_end_column(mp_rdataWriter, col3);

rdata_begin_column(mp_rdataWriter, col4, 2);
rdata_append_string_value(mp_rdataWriter, "bla");
rdata_append_string_value(mp_rdataWriter, "blo");
rdata_end_column(mp_rdataWriter, col4);

rdata_end_table(mp_rdataWriter, 2, "Test table 2");

rdata_end_file(mp_rdataWriter);
close(fd);

and

ssize_t
McqrRdata::write_data(const void *bytes, size_t len, void *ctx)
{
  int fd = *(int *)ctx;
  return write(fd, bytes, len);
}

Thank you

Thomas

@evanmiller
Copy link
Collaborator

Thanks for the report. This looks like a bug. I'll leave it open until I get a chance to look into it.

@evanmiller evanmiller added the bug label Jan 7, 2021
@evanmiller
Copy link
Collaborator

One issue is that each table will iterate over all of the writer's columns when writing the "names" and "var.labels" attributes. The columns need to be associated with the individual tables rather than the writer object somehow.

@cgilles
Copy link

cgilles commented Jul 28, 2023

Hi,

I'm faced exactly the same problem in my project exporting multiple tables in the same RData file. The file is created but it's impossible to load the file in R.

Creating one table work fine, more than one no.

Best

Gilles Caulier

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

No branches or pull requests

3 participants