From 85e4408b90b4a4fb5de59a0c283671ad21a3397c Mon Sep 17 00:00:00 2001 From: garborg Date: Sun, 9 Mar 2014 09:49:56 -0500 Subject: [PATCH] Ensure column names are valid identifiers. Closes #520 --- src/RDA.jl | 4 ++-- test/RDA.jl | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/RDA.jl b/src/RDA.jl index 019b827ce3..5bfbff74b7 100644 --- a/src/RDA.jl +++ b/src/RDA.jl @@ -306,5 +306,5 @@ function data(rc::RComplex) BitArray(imag(rc.data) .== R_NA_FLOAT64)) end -DataFrame(rl::RList) = DataFrame(map(x->data(x), rl.data), - Symbol[symbol(x) for x in rl.attr["names"].data]) +DataFrame(rl::RList) = DataFrame(map(x->data(x), rl.data), + Symbol[identifier(x) for x in rl.attr["names"].data]) diff --git a/test/RDA.jl b/test/RDA.jl index 0c6c41aeb7..95a12acada 100644 --- a/test/RDA.jl +++ b/test/RDA.jl @@ -8,9 +8,9 @@ module TestRDA # save(df, file='minimal.rda') # df['int'] = c(1L, 2L) - # df['logi'] = c(T, F) + # df['logi'] = c(TRUE, FALSE) # df['chr'] = c('ab', 'c') - # df['factor'] = factor(df[['chr']]) + # df['factor'] = factor(df$chr) # #utf=c('Ж', '∰')) R handles it, read_rda doesn't. # save(df, file='types.rda') @@ -18,6 +18,9 @@ module TestRDA # df['chr'] = NULL # NA characters breaking read_rda # save(df, file='NAs.rda') + # names(df) = c('end', '!', '1', '%_B*\tC*') + # save(df, file='names.rda') + testdir = dirname(@__FILE__) df = DataFrame(num = [1.1, 2.2]) @@ -32,4 +35,7 @@ module TestRDA df[2, :] = NA df = df[:, [:num, :int, :logi, :factor]] # (NA) chr breaks read_rda @test isequal(DataFrame(read_rda("$testdir/data/RDA/NAs.rda")["df"]), df) + + rda_names = names(DataFrame(read_rda("$testdir/data/RDA/names.rda")["df"])) + @test rda_names == [:_end, :x!, :x1, :B_C] end