From 0a3d229a800e2f6bf1400b9d9e6152bbbacd03e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net> Date: Fri, 10 Mar 2023 13:20:16 +0100 Subject: [PATCH] additional argument to appendlabel! --- Project.toml | 2 +- src/Datasets.jl | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 148daa5..ba8f3b2 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 5f655c0..69ade64 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 -- GitLab