diff --git a/Project.toml b/Project.toml index 148daa51ddf27d5552a2a8a0a2a563891e5480ed..ba8f3b2ed393eb9a199e302724f445f8de07ba58 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PlanarLarvae" uuid = "c2615984-ef14-4d40-b148-916c85b43307" authors = ["François Laurent", "Institut Pasteur"] -version = "0.9.1" +version = "0.9.2" [deps] DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" diff --git a/src/Datasets.jl b/src/Datasets.jl index 5f655c072c36df8790c922bc8bdd85c10409a486..69ade6469551642a4f9e4004cccc0fbdac1f07ee 100644 --- a/src/Datasets.jl +++ b/src/Datasets.jl @@ -1138,16 +1138,21 @@ coerce(ref::AbstractVector, a) = coerce(eltype(ref), a) coerce(ref, a) = coerce(typeof(ref), a) """ - appendlabel!(run, label; recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[]) + appendlabel!(run, label; recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[], ifempty=true) Append a label to existing labels, at every track steps. Per default, the label to append is considered secondary, meaning it is represented appart in the metadata. Secondary labels are recorded as such in metadata, so that they can be distinguished from primary labels. + Argument `ignore` lists uncompatible labels that prevent the label to be appended. + +Argument `ifempty`, if set to false, additionally allows preventing the specified label to be +appended in cases the label is explicitly undefined with an empty list of labels. """ function appendlabel!(run::Run, label::Union{Symbol, String}; - recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[]) + recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[], + ifempty=true) decodelabels!(run) topattr = attrname isa Symbol ? attrname : attrname[1] labels = if topattr== recordname @@ -1178,7 +1183,9 @@ function appendlabel!(run::Run, label::Union{Symbol, String}; for (i, existinglabel) in enumerate(labels) if isa(existinglabel, Vector) if isempty(existinglabel) - labels[i] = label # not a vector + if ifempty + labels[i] = label # not a vector + end elseif isempty(existinglabel ∩ ignore) push!(existinglabel, label) end