What is a good use of the 'comment' function in R? I just discovered the comment function in R.  Example:
x <- matrix(1:12, 3,4)
comment(x) <- c("This is my very important data from experiment #0234",
                "Jun 5, 1998")
x
comment(x)

This is the first time I came by this function and was wondering what are common/useful uses of it.
Since it is quite difficult to search "R comment" in google and find relevant results, I was hoping someone here might share with his experience.
 A: Similar facilities exist in other packages, such as the -notes- command in Stata. We use this to document full details of a variable, e.g. details of assay for a biochemical measurement, or exact wording of the question asked for questionnaire data. This is often too much info for the variable name or label, one or both of which are displayed in the output of every analysis involving the variable and are therefore best kept reasonably short.
A: One of the things I find myself doing a lot is tracking the commands used to generate data and objects, and have found the comment to be a useful tool for this.
The 'matched.call.data' and 'generate.command.string' do the trick.  Not perfect, but helpful and a use for 'comment()'. :)
# Comments only accept strings...
# Substituting the escaped quotes ('\"') makes it prettier.
generate.command.string <- function( matched.call.data )
{
  command.string <- as.character( bquote( .( list( matched.call.data ) ) ) )
  sapply( bquote( .(command.string) ),
                  USE.NAMES=FALSE,
                  function( x )
                    gsub( "\\\"", "\'", as.list( match.call() )$x )[[2]] )
}

# Some generating function...
generate.matrix <- function( nrows, ncols, data=NA ) {
  # Some generated object
  mat <- matrix( data= data, nrow= nrows, ncol= ncols )

  matched.call.data <- do.call( "call",
                                c( list( as.character( match.call()[[1]] ) ),
                                lapply( as.list( match.call() )[-1], eval ) ) )
  comment( mat ) <- c( Generated= date(),
                       Command = generate.command.string( matched.call.data ) )

  mat
}

# Generate an object with a missing argument.
emptyMat <- generate.matrix( nrows=2, ncols=2 )
comment( emptyMat )

# Generate without formally stating arguments.
dataMat <- generate.matrix( 2, 2, sample(1:4, 4, replace= TRUE ) )
comment( dataMat )

# And with a longer command.
charMat <- generate.matrix( 3, 3,
                  c( 'This', 'is', 'a', 'much', 'longer',
                     'argument', 'section', 'that', 'wraps') )
comment( charMat )

# And with a variable.
myData <- c( 'An', 'expanded', 'command', 'argument')
charMat2 <- generate.matrix( 2, 2, myData )
comment( charMat2 )

# Create a new object from an original command.
Sys.sleep(1)
emptyMat2 <- eval( parse( text= comment( emptyMat )[['Command']] ) )
dataMat2 <- eval( parse( text= comment( emptyMat )[['Command']] ) )

# Check equality of the static matrices.
identical( emptyMat, emptyMat2 )

# The generation dates are different.
all.equal( emptyMat, emptyMat2, check.attributes= FALSE )
comment( emptyMat )['Generated'] <- NA
comment( emptyMat2 )['Generated'] <- NA
identical( emptyMat, emptyMat2 )

# Command argument structure still works too.
str( as.list( match.call(
  generate.matrix, parse( text=comment( charMat2 )[[ 'Command' ]] ) ) )[-1] )

A: Allow me to suggest my general solution to object management in R: the repo package. Using it, you can assign each variable a long name, a description, a set of tags, a remote url, dependency relations and also attach figures or generic external files. For example, source code can be stored as a repository item and attached to resources produced by it. Find the latest stable release on CRAN (install.packages("repo")) or the latest development on github. A quick overview here. Hope it helps.
A: To second @Gavin, Frank Harrell has developed efficient ways to handle annotated data.frame in R in his Hmisc package. For example, the label() and units() functions allow to add dedicated attributes to R objects. I find them very handy when producing summary of data.frame (e.g., with describe()).
Another useful way of using such an extra attribute is to apply a timestamp on a data set. I also add an attribute for things like random seed, fold number (when I use k-kold or LOO cross-validation).
A: One thing I often find myself doing in my R scripts for a particular data analysis task is to include comments in the script about the units of variables in my data frames. I work with environmental data and chemists and ecologists seem to enjoy using a wide range of different units for the same things (mg L$^{-1}$ vs mu eq L$^{-1}$, etc). My colleagues usually store this information in the row immediately below the column names in Excel sheets.
I'd see comment() as a nice way of attaching this information to a data frame for future reference.
