From ripley at stats.ox.ac.uk  Wed Oct 19 22:30:17 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 19 Oct 2011 21:30:17 +0100 (BST)
Subject: [Rd] list of operations that preserve attributes
In-Reply-To: <4E9F2813.6010904@uottawa.ca>
References: <4E9F2813.6010904@uottawa.ca>
Message-ID: <alpine.LFD.2.02.1110192125470.7044@gannet.stats.ox.ac.uk>

There is a description in the 'Blue Book' (Becker et al, 1988) of when 
attributes are supposed to be preserved, and R mostly conforms to it.

This is discussed somewhere relevant in the R documentation:  I would 
have to search for exactly where, so I leave that to you.

On Wed, 19 Oct 2011, John C Nash wrote:

> I've been trying to prepare some wrappers for optimization objective functions and
> gradients that use try() to check for computable functions. I'm also trying to do scaling
> as per optim() so that a number of methods that are available on CRAN and R-Forge can use
> parameter and function scaling. This got me into minor trouble when I scaled a gradient or
> Hessian and the "inadmissible" attribute I had created suddenly disappeared. When I
> discovered why -- that some operations don't preserve attributes -- I started to look for
> a list of which ops preserve attributes and which don't. The code snippet below shows that
> matrix multiplication (%*%) does not, while multiplication by a vector (simple *) does.
> I'm not really surprised that some ops don't preserve attributes, particularly those that
> are binary like multiplication, but it might be nice to know which operations and special
> functions do so.
>
> rm(list=ls())
> m<-matrix(1:4,nrow=2, ncol=2)
> print(m)
> attributes(m)
> attr(m,"check")<-"***"
> attributes(m)
> bigm<-10*m
> str(bigm)
> bigm1<-diag(c(1,1))%*%m
> str(bigm1)
> bigm1<-c(1,2)*m
> str(bigm1)
> print(bigm1)
> arraym<-as.array(m)
> str(arraym)
> tanm<-tan(m)
> str(tanm)
>
>
> Best,
>
> John Nash
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] list of operations that preserve attributes
Prof Brian Ripley