Skip to content

Commit

Permalink
Ensure column names are valid identifiers. Closes #520
Browse files Browse the repository at this point in the history
  • Loading branch information
garborg committed Mar 9, 2014
1 parent e285dc8 commit 85e4408
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/RDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
10 changes: 8 additions & 2 deletions test/RDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ 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')

# df[2, ] = NA
# 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])
Expand All @@ -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

0 comments on commit 85e4408

Please sign in to comment.