Skip to content
Prev 6064 / 63468 Next

Variable labels (was Re: [R] Reading SAS version 8 data into

"Warnes, Gregory R" wrote:
Thanks for your reply Greg.
The "complex" code I was referring to was the eval()
and as.name() parts of your code.  The deparse can be
handy although I have done that on a case-by-case basis.
For example in a high-level plotting function I'll retrieve
label(an argument) and if that is empty I'll use
deparse(substitute(argument)).
Right.  That's why I try to define labels early when a data
frame is being created (e.g, in sas.get).
Mine are simple:

label <- function(x)  {
	lab<-attr(x, "label")
	if(is.null(lab))lab<-""
	lab
	}

#From Bill Dunlap, StatSci  15Mar95:

"label<-" <- if(!.SV4.) function(x, value)
  structure(x, label=value,
            class=c('labelled',
              attr(x,'class')[attr(x,'class')!='labelled'])) else
function(x, value) {    # 1Nov00 for Splus 5.x, 6.x
  attr(x,'label') <- value
  x
}

For non SV4 systems (which include R) you see above that
when putting a label on a variable a class "labelled" is
added.  This is really to handle the subsetting problem
but I would rather get rid of it if subsetting can
respect selected attributes.
If the user or a package specifies the list of attribute names
to preserve (I can only think of 'label' and 'units' right now)
I don't see a downside.  -Frank