[Rd] Five functions proposed for base
Arni Magnusson
arnima at u.washington.edu
Wed Aug 20 14:00:30 MEST 2003
Dear r-devel,
Among the R functions I have written and later shared with colleagues,
there are five that I hope will become a part of the R base package. The
tasks are neither specific nor marginal, so rather than creating one more
'misc' package, I would be happy if the R Development Core Team would
adopt these functions and hammer them into shape.
The functions are available from http://students.washington.edu/arnima/s,
and a short demo session below explains their behaviour. Sorry about the
length of this message, but it should be quick read.
> env()
Environment Objects Kb
1 .GlobalEnv 19 982
2 package:lme4 180 992
3 file:f:/gnu/home/r/toolbox.rdata 49 457
4 Autoloads 44 0
5 package:base 1657 8196
These environments are currently loaded. Verbose version of search().
> ll()
Class Kb
chinook data.frame 66
chinook.0 glm 244
coho data.frame 127
coho.0 glm 466
fig2 function 21
fig3 function 13
table3 data.frame 1
table4 data.frame 2
x numeric 1
y integer 1
z list 5
My workspace contains these objects. Verbose version of ls(). I think
package:R.oo provides something similar.
> elem(coho)
Class Kb
<row.names> character 21
Species factor 7
Estuary ordered 8
EstSize factor 7
EstSizeLog numeric 14
EstNatural numeric 14
Oyster factor 7
RelYear factor 7
SSTsummer numeric 14
Survival numeric 14
TxF numeric 14
The coho data frame contains these elements. Compactly describes the data
frame, not overlapping with summary() or describe() in package:Hmisc.
I use this function when choosing appropriate storage mode for elements in
large data frames. It has also helped me locating errors in imported data
(numbers containing both . and , decimal seperator are flagged by factor).
> elem(coho.0, dim=T)
Class Kb Dim
coefficients numeric 0 1
residuals numeric 35 1768
fitted.values numeric 35 1768
effects numeric 35 1768
R matrix 0 1 x 1
rank integer 0 1
qr list 35 5
family family 7 11
linear.predictors numeric 35 1768
deviance numeric 0 1
aic numeric 0 1
null.deviance numeric 0 1
iter integer 0 1
weights numeric 35 1768
prior.weights numeric 35 1768
df.residual numeric 0 1
df.null numeric 0 1
y numeric 35 1768
converged logical 0 1
boundary logical 0 1
model data.frame 50 1768 x 2
call call 1 5
formula formula 0 3
terms terms 1 3
data data.frame 127 1768 x 10
offset NULL 0
control list 0 3
method character 0 1
contrasts NULL 0
xlevels NULL 0
Gives me a good idea about the elements of this GLM.
> is.what(y)
[1] "is.atomic" "is.finite" "is.integer" "is.numeric" "is.vector"
Now I know which is.* tests are positive on an integer object. Inspired by
demo(is.things).
> keep(fig2, fig3)
[1] "chinook" "chinook.0" "coho" "coho.0" "table3" "table4"
[7] "x" "y" "z"
Shows which objects will be removed, if I'm sure.
> keep(fig2, fig3, sure=T)
Default workspace has been cleared, only fig2 and fig3 were kept.
---
I understand that functions for the base package have to be selected very
carefully, but I believe the functions above can save a significant amount
of time and effort for many R users. My implementations are reasonably
generic and robust, but I'm hoping the R Development Core Team will adopt
and improve improve them.
Regards,
Arni Magnusson (fish biologist)
More information about the R-devel
mailing list