Skip to content

Commit dfb82a5

Browse files
authored
Merge pull request #11 from PharmCat/dev
col names when int used
2 parents 4626d10 + e54dd06 commit dfb82a5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.github/workflows/Tier1.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ${{ matrix.os }}
2424
strategy:
2525
matrix:
26-
julia-version: [1.6, 1.7, 1.8]
26+
julia-version: [1.6, 1.8, 1]
2727
julia-arch: [x64]
2828
os: [ubuntu-latest, macOS-latest, windows-latest]
2929
steps:

src/descriptive.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Import data.
128128
"""
129129
function dataimport(data; vars, sort = nothing)
130130
if isa(vars, Symbol) vars = [vars] end
131-
131+
if eltype(vars) <: Integer vars = Tables.columnnames(data)[vars] end
132132
if !isnothing(sort) && isa(sort, Symbol) sort = [sort] end
133133

134134
dataimport_(data, vars, sort)
@@ -157,7 +157,7 @@ function dataimport_(data, vars::AbstractVector, sort::AbstractVector)
157157
end
158158
return DataSet(identity.(sdata))
159159
end
160-
function dataimport_(data, vars, sort::Nothing)
160+
function dataimport_(data, vars, ::Nothing)
161161
sdata = Vector{ObsData}(undef, length(vars))
162162
for i in 1:length(vars)
163163
sdata[i] = ObsData(Tables.getcolumn(data, vars[i]), vars[i], Dict(:Variable=>vars[i]))
@@ -209,6 +209,7 @@ function descriptives(data, vars, sort = nothing; kwargs...)
209209
if isa(vars, Symbol) vars = [vars] end
210210
if isa(sort, String) sort = [Symbol(sort)] end
211211
if isa(sort, Symbol) sort = [sort] end
212+
if eltype(vars) <: Integer vars = Tables.columnnames(data)[vars] end
212213
if !isnothing(sort)
213214
vars = setdiff(vars, sort)
214215
end
@@ -228,6 +229,7 @@ function descriptives(data; vars = nothing, sort = nothing, kwargs...)
228229
end
229230
if length(vars) == 0 error("No column found for descriptive statistics!") end
230231
end
232+
if eltype(vars) <: Integer vars = Tables.columnnames(data)[vars] end
231233
descriptives(data, vars, sort; kwargs...)
232234
end
233235
"""
@@ -475,7 +477,7 @@ end
475477
#
476478
################################################################################
477479

478-
function MetidaBase.metida_table(obj::DataSet{DS}; sort = STATLIST, stats = nothing, id = nothing) where DS <: Descriptives
480+
function MetidaBase.metida_table(obj::DataSet{DS}; sort = nothing, stats = nothing, id = nothing) where DS <: Descriptives
479481
idset = Set(keys(first(obj).data.id))
480482
resset = Set(keys(first(obj).result))
481483
if length(obj) > 1
@@ -484,12 +486,21 @@ function MetidaBase.metida_table(obj::DataSet{DS}; sort = STATLIST, stats = noth
484486
union!(resset, Set(keys(obj[i].result)))
485487
end
486488
end
489+
487490
if !isnothing(stats)
488491
stats STATLIST || error("Some statistics not known!")
489492
if isa(stats, Symbol) stats = [stats] end
490-
ressetl = sortbyvec!(collect(intersect(resset, stats)), sort)
493+
if isnothing(sort)
494+
ressetl = collect(intersect(resset, stats))
495+
else
496+
ressetl = sortbyvec!(collect(intersect(resset, stats)), sort)
497+
end
491498
else
492-
ressetl = sortbyvec!(collect(resset), sort)
499+
if isnothing(sort)
500+
ressetl = collect(resset)
501+
else
502+
ressetl = sortbyvec!(collect(resset), sort)
503+
end
493504
end
494505
if !isnothing(id)
495506
if isa(id, Symbol) id = [id] end

0 commit comments

Comments
 (0)