@@ -224,17 +224,20 @@ private void doSendFiles() {
224
224
* Read the CSV file in the R workspace with the appropriate data types.
225
225
*/
226
226
private void doReadCSVFile () {
227
- log .debug ("Reading the CSV file into a tibble" );
228
- ensurePackage ("readr" );
229
- ensurePackage ("labelled" );
230
- eval (String .format ("base::source('%s')" , COLS_FILE_NAME ));
231
- eval (String .format ("base::is.null(base::assign('%s', readr::read_csv('%s', col_types = .cols)))" , getSymbol (tableName ), DATA_FILE_NAME ));
232
- eval ("base::rm(.cols)" );
233
- eval (String .format ("base::source('%s')" , ATTR_FILE_NAME ));
234
- eval (String .format ("base::unlink('%s')" , DATA_FILE_NAME ));
235
- eval (String .format ("base::unlink('%s')" , COLS_FILE_NAME ));
236
- eval (String .format ("base::unlink('%s')" , ATTR_FILE_NAME ));
237
- log .debug ("Symbol {} assigned" , getSymbol (tableName ));
227
+ try {
228
+ log .debug ("Reading the CSV file into a tibble" );
229
+ ensurePackage ("readr" );
230
+ ensurePackage ("labelled" );
231
+ eval (String .format ("base::source('%s')" , COLS_FILE_NAME ));
232
+ eval (String .format ("base::is.null(base::assign('%s', readr::read_csv('%s', col_types = .cols)))" , getSymbol (tableName ), DATA_FILE_NAME ));
233
+ eval ("base::rm(.cols)" );
234
+ eval (String .format ("base::source('%s')" , ATTR_FILE_NAME ));
235
+ log .debug ("Symbol {} assigned" , getSymbol (tableName ));
236
+ } finally {
237
+ eval (String .format ("base::unlink('%s')" , DATA_FILE_NAME ));
238
+ eval (String .format ("base::unlink('%s')" , COLS_FILE_NAME ));
239
+ eval (String .format ("base::unlink('%s')" , ATTR_FILE_NAME ));
240
+ }
238
241
}
239
242
240
243
}
@@ -309,9 +312,9 @@ else if (variable.getValueType().equals(DecimalType.get()))
309
312
type = "double" ;
310
313
else if (variable .getValueType ().equals (BooleanType .get ()))
311
314
type = "logical" ;
312
- else if (variable .getValueType ().equals (DateType .get ()))
315
+ else if (variable .getValueType ().equals (DateType .get ()) && ! variable . hasCategories () )
313
316
type = "date" ;
314
- else if (variable .getValueType ().equals (DateTimeType .get ()))
317
+ else if (variable .getValueType ().equals (DateTimeType .get ()) && ! variable . hasCategories () )
315
318
type = "datetime" ;
316
319
else
317
320
type = "character" ;
@@ -361,7 +364,7 @@ private void writeVariableAttributes(Variable variable) {
361
364
}
362
365
// obiba/opal#3829 enforce haven to read spss missings properly
363
366
attributesWriter .println (String .format ("class(`%s`[['%s']]) <- c('haven_labelled_spss', class(`%s`[['%s']]))" ,
364
- getSymbol (tableName ), variable .getName (), getSymbol (tableName ), variable .getName ()));
367
+ getSymbol (tableName ), variable .getName (), getSymbol (tableName ), variable .getName ()));
365
368
}
366
369
labels = String .format ("c(%s)" , Joiner .on (", " ).join (getLabelledCategories (variable , variable .getCategories ())));
367
370
}
0 commit comments