Environment.SetSymbol is documented as a method which "Defines a symbol in this environment." However, the underlying R function (Rf_SetVar) has this comment:
Assign a new value to bound symbol. Note this does the "inherits"
case. I.e. it searches frame-by-frame for a symbol and binds the
given value to the first symbol encountered. If no symbol is
found then a binding is created in the global environment.
I believe Rf_defineVar is the R function which behaves as documented for SetSymbol.
Here is an example showing the current behavior:
var env = engine.Evaluate("list2env(list(a=5))").AsEnvironment();
Console.WriteLine(String.Join(", ", env.GetSymbolNames()));
env.SetSymbol("b", engine.CreateIntegerVector(new int[] { 6 }));
Console.WriteLine(String.Join(", ", env.GetSymbolNames()));
Console.WriteLine(String.Join(", ", engine.GlobalEnvironment.GetSymbolNames()));
outputs:
a
a
b
Assign a new value to bound symbol. Note this does the "inherits"
case. I.e. it searches frame-by-frame for a symbol and binds the
given value to the first symbol encountered. If no symbol is
found then a binding is created in the global environment.
I believe Rf_defineVar is the R function which behaves as documented for SetSymbol.
Here is an example showing the current behavior:
var env = engine.Evaluate("list2env(list(a=5))").AsEnvironment();
Console.WriteLine(String.Join(", ", env.GetSymbolNames()));
env.SetSymbol("b", engine.CreateIntegerVector(new int[] { 6 }));
Console.WriteLine(String.Join(", ", env.GetSymbolNames()));
Console.WriteLine(String.Join(", ", engine.GlobalEnvironment.GetSymbolNames()));
outputs:
a
a
b