Skip to content

Commit

Permalink
Update get_df_from_binary.cpp
Browse files Browse the repository at this point in the history
R data types doesn't support SHORT and FLOAT (it refers to INTEGER and NUMERIC). So, instead of directly declaring IntergetVector or NumericVector to store SHORT or FLOAT values, assign them to interim primitive types and then pass them to respective vectors. This is not my favorite style and may revise once I have enumerated a new datatype to handle this. This should fix #15.
  • Loading branch information
Amar committed Mar 24, 2016
1 parent caa25ae commit e0cf0e3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/get_df_from_binary.cpp
Expand Up @@ -77,12 +77,15 @@ List get_df_from_binary(
// Short fields (integer)
} else if(type[i] == "S"){
IntegerVector current_vec(n_rows);

short x;

for (int j = 0; j < n_rows; j++){
line_pos = j * row_length + start[i] - 1;
bf.seekg(line_pos, ios::beg);

bf.read((char*)&current_vec[j], 2);
// bf.read((char*)&current_vec[j], 2);

This comment has been minimized.

Copy link
@4Step

4Step Mar 24, 2016

Contributor

I should have deleted these comments. Bad habit of commenting codes instead of deleting them.

bf.read((char*)&x, 2);
current_vec[j] = x;
if(current_vec[j] == short_miss){
current_vec[j] = NA_INTEGER;
}
Expand All @@ -107,12 +110,15 @@ List get_df_from_binary(
// Float fields (single)
} else if(type[i] == "F"){
NumericVector current_vec(n_rows);

float x;

for (int j = 0; j < n_rows; j++){
line_pos = j * row_length + start[i] - 1;
bf.seekg(line_pos, ios::beg);

bf.read((char*)&current_vec[j], 4);
// bf.read((char*)&current_vec[j], 4);

This comment has been minimized.

Copy link
@4Step

4Step Mar 24, 2016

Contributor

Delete this

bf.read((char*)&x, 4);
current_vec[j] = x;
if(current_vec[j] == flt_miss){
current_vec[j] = NA_REAL;
}
Expand Down

0 comments on commit e0cf0e3

Please sign in to comment.