Hello all, I recently discovered the "comment" command. I see it can only hold a vector of characters. Is there a way (or an alternative), to make it possible to have it keep a list? (for example, to keep different pieces of information like date of creation, information of each variable and so on) The closest solution I can think of is using 'names' on the vector, like this: x <- 1 comment(x) <- letters names(comment(x)) <- LETTERS x comment(x) Any other suggestions? (or general best practices for the "comment" command ?) Thanks, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Henrique Dallazuanna
2010-Nov-09 11:08 UTC
[R] Is there a way to have 'comment' keep a list?
You can use attributes: attributes(x) <- list(CreateDate = Sys.time(), User = Sys.info()['user']) On Tue, Nov 9, 2010 at 8:36 AM, Tal Galili <tal.galili@gmail.com> wrote:> Hello all, > > I recently discovered the "comment" command. > I see it can only hold a vector of characters. > > Is there a way (or an alternative), to make it possible to have it keep a > list? > (for example, to keep different pieces of information like date of > creation, > information of each variable and so on) > > The closest solution I can think of is using 'names' on the vector, like > this: > x <- 1 > comment(x) <- letters > names(comment(x)) <- LETTERS > x > comment(x) > > > Any other suggestions? > (or general best practices for the "comment" command ?) > > Thanks, > Tal > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili@gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Look at the help page, the example does exactly this by putting a two
element vector of strings as comment.
Hope it helps
mario
On 09-Nov-10 11:36, Tal Galili wrote:> Hello all,
>
> I recently discovered the "comment" command.
> I see it can only hold a vector of characters.
>
> Is there a way (or an alternative), to make it possible to have it keep a
> list?
> (for example, to keep different pieces of information like date of
creation,
> information of each variable and so on)
>
> The closest solution I can think of is using 'names' on the vector,
like
> this:
> x<- 1
> comment(x)<- letters
> names(comment(x))<- LETTERS
> x
> comment(x)
>
>
> Any other suggestions?
> (or general best practices for the "comment" command ?)
>
> Thanks,
> Tal
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili at gmail.com | 972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
----------------------------------------------------------------------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Ing. Mario Valle
Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
I hadn't seen 'comment' before, so don't take my suggestion as
authoritative. It looks useful, so I investigated a bit.
This technique seems to work and is (perhaps?) easier than names:
tlist <- list(a=c(1:3), b=7)
comment(x) <- unlist(sapply(tlist, as.character))
or in one line
comment(x) <- unlist(sapply(list(a=c(1:3), b=7), as.character))
If at least one of the list elements is already character you could simplify
to:
tlist <- list(a=c(1:3), b="fred")
comment(x) <- unlist(tlist)
or in one line
comment(x) <- unlist(list(a=c(1:3), b="fred"))
Not as nice as having a _real_ list, but I guess that would really be a case
for attributes
HTH
Keith J
"Tal Galili" <tal.galili at gmail.com> wrote in message
news:AANLkTimpMMa9_h1+=Oj1BHRf27rLp2J5VeoDHJxQpNxd at
mail.gmail.com...> Hello all,
>
> I recently discovered the "comment" command.
> I see it can only hold a vector of characters.
>
> Is there a way (or an alternative), to make it possible to have it keep a
> list?
> (for example, to keep different pieces of information like date of
> creation,
> information of each variable and so on)
>
> The closest solution I can think of is using 'names' on the vector,
like
> this:
> x <- 1
> comment(x) <- letters
> names(comment(x)) <- LETTERS
> x
> comment(x)
>
>
> Any other suggestions?
> (or general best practices for the "comment" command ?)
>
> Thanks,
> Tal
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili at gmail.com | 972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
----------------------------------------------------------------------------------------------
>
> [[alternative HTML version deleted]]
>