[R] unit attribute to list elements
ba208 at exeter.ac.uk
Fri Dec 28 20:33:02 CET 2007
I've started my own (first) package, part of which consists in
listing common physical constants (Planck's constant, the speed of
light in vacuum, etc). I'm wondering what would be a good way of
dealing with pairs of value/unit.
> constants <- list( cel = 2.99792458e8 , #m/s
> Z0 = 376.730313461, #ohm
> eps0 = 8.854187817e-12,#F/m
> mu0 = 4*pi*1e-7,#N/A^2
> G = 6.67428e-11 # m^3 kg-1 s-2
I thought I could include the unit in the names attribute of each
element, as in :
> names(constants$cel)<- " speed of light in vacuum [m.s^-1]"
Writing this for every element is very redundant... Is there any way
to access and set the name of each first level element of the list?
> namesFirstLevelElements(constants)<- c(" speed of light in vacuum
> "impedance of vacuum [some unit]",
Quite possibly, I'm completely on the wring track;
- maybe such a package already exists
- a custom class or structure would be more appropriate? I don't
really know how to deal with classes, though, and I'd like to keep
the access to the constants' values as direct and generic as possible.
Many thanks in advance,
University of Exeter
EX4 4QL, UK
Phone: +44 1392 264187
More information about the R-help