From aa21610e4c4731865f7ba0c3e36922bd73296647 Mon Sep 17 00:00:00 2001 From: PharmCat Date: Wed, 25 Aug 2021 02:36:41 +0300 Subject: [PATCH] append! --- Project.toml | 2 +- src/types.jl | 8 ++++++++ test/runtests.jl | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7f04e3f..6c541d2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaBase" uuid = "075456b7-4006-432f-9324-2f8453996c49" authors = ["PharmCat and contributors"] -version = "0.4.0" +version = "0.4.1" [deps] #StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" diff --git a/src/types.jl b/src/types.jl index bcf8de9..665c626 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 494ab00..3e489c8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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