Skip to content

Commit

Permalink
append!
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Aug 24, 2021
1 parent d79bf10 commit aa21610
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaBase"
uuid = "075456b7-4006-432f-9324-2f8453996c49"
authors = ["PharmCat <[email protected]> and contributors"]
version = "0.4.0"
version = "0.4.1"

[deps]
#StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Expand Down
8 changes: 8 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ function Base.setindex!(t::MetidaTable, val, row::Int, ind::T) where T <: Union{
Tables.getcolumn(t, ind)[row] = val
end

function Base.append!(t::MetidaTable, t2::MetidaTable)
if !(names(t) names(t2)) error("Names for t not in t2") end
for n in names(t)
append!(t[:, n], t2[:, n])
end
t
end

function Base.pushfirst!(t::MetidaTable, row::AbstractVector)
if length(row) != length(keys(t.table)) error("Size not equal") end
i = 1
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ using Test, DataFrames, CSV
@test mt[i, :b] == j[2]
end

l1 = length(mt)
mt2 = MetidaBase.metida_table([1,2,3], ["a", "b", "c"], names = (:a, :b))
append!(mt, mt2)
@test l1 + length(mt2) == length(mt)
mt2 = MetidaBase.metida_table(["e", "f", "g"], [1,2,3], names = (:b, :a))
append!(mt, mt2)

CSV.write(io, mt)

struct ExampleIDStruct <: MetidaBase.AbstractSubject
Expand Down

0 comments on commit aa21610

Please sign in to comment.