Well, it can be done without a temporary variable, but I'm not sure you
would want to.
Anyway...
## simplified example
> a <- 1
> vname <- "a"
> eval(substitute(attr(x,"b") <- "hi", list( x = as.name(vname
> a
[1] 1
attr(,"b")
[1] "hi"
Cheers,
Bert
Bert Gunter
"The trouble with having an
oops, I think the right code would be
x = get(varname)
attr(x, "foo") = "bar"
assign(varname, x)
On Wed, Oct 10, 2018 at 9:30 PM Peter Langfelder
wrote:
> I would try something like
>
> x = get(myvarname)
> attr(x, "foo") = "bar"
> assign(varname, x)
>
> HTH,
>
> Peter
>
> On Wed, Oct 10, 2018
I would try something like
x = get(myvarname)
attr(x, "foo") = "bar"
assign(varname, x)
HTH,
Peter
On Wed, Oct 10, 2018 at 9:15 PM Marc Girondot via R-help <
r-help@r-project.org> wrote:
> Hello everybody,
>
> Has someone the solution to set attribute when variable is known by name ?
>
> Thank
Hello everybody,
Has someone the solution to set attribute when variable is known by name ?
Thanks a lot
Marc
Let see this exemple:
# The variable name is stored as characters.
varname <- "myvarname"
assign(x = varname, data.frame(A=1:5, B=2:6))
attributes(myvarname)
$names
[1] "A" "B"
$cla
4 matches
Mail list logo