David Varela has the correct answer, "use merge". It is an important technique.
- To make this solution more easily available to others, here are some examples.
on creating plain Tuples (unnamed Tuples) and NamedTuples
Both Tuples and NamedTuples are constructed using parentheses:
julia> a_tuple = (1, 2)
(1, 2)
julia> a_namedtuple = (a = 1, b = 2)
(a = 1, b = 2)
If we try construct a Tuple or a NamedTuple with exactly one entry that same way, it does not work; instead the values are assigned named variables directly.
julia> not_a_tuple = ("xyz");
julia> not_a_tuple, typeof(not_a_tuple)
("xyz", String)
julia> not_a_namedtuple = (abc = "xyz");
julia> not_a_namedtuple, typeof(not_a_namedtuple)
("xyz", String)
To construct Tuples and NamedTuples that have a single value, we let Julia know that we are working with [Named]Tuples. An easy way to do this, and one that works for both kinds of Tuples, is to add a comma ',' before the closing parenthesis. For visual emphasis, I separate the commas from the values; it is not necessary to do that in your source code.
julia> a_tuple = (0.5 ,)
(0.5,)
julia> a_namedtuple = (onehalf = 0.5 ,)
(onehalf = 0.5,)
on substituting values in NamedTuples
julia> namedtuple = (a = 1, b = 2, c = 3); # the initial NamedTuple
julia> changes_to_make = (b = 0 ,); # the modifications intended
julia> changed_namedtuple = merge(namedtuple, changes_to_make)
(a = 1, b = 0, c = 3)
julia> namedtuple = (a = 1, b = 2, c = 3); # the initial NamedTuple
julia> changes_to_make = (b = 0, c = 7); # the modifications intended
julia> changed_namedtuple = merge(namedtuple, changes_to_make)
(a = 1, b = 0, c = 7)