Hmisc labels and captions in latex.list()
Thanks, Frank. I am an old newbie, so your advice was not straightforward to me, but it nudged me to look at the structure of the contents object. I did solve the problem by passing the contents data frame in the contents object. Using the example dfr from Dieter, > g <- contents(dfr) > g Data frame:dfr 20 observations and 2 variables Maximum # NAs:0 Levels Storage x double y 2 integer +--------+-----------+ |Variable|Levels | +--------+-----------+ | y |female,male| +--------+-----------+ > str(g) List of 6 $ contents :'data.frame': 2 obs. of 2 variables: ..$ Levels : int [1:2] 0 2 ..$ Storage: Factor w/ 2 levels "double","integer": 1 2 $ dim : int [1:2] 20 2 $ maxnas : int 0 $ dfname : chr "dfr" $ Levels :List of 1 ..$ y: chr [1:2] "female" "male" $ longLabels: NULL - attr(*, "class")= chr "contents.data.frame" > g$contents Levels Storage x 0 double y 2 integer latex(g$contents, caption='hello', label='mylabel',file='') This may be useful to others. But sounds like this has not been a high traffic issue! - Mike
On Dec 30, 2008, at 8:35 AM, Frank E Harrell Jr wrote:
J Michael Dean wrote:
Thanks, Dieter, for your response shown below.
library(Hmisc)
dfr <- data.frame(x=rnorm(20),y=sample(c('male','female'),20,TRUE))
cnt <- contents(dfr)
latex(cnt,label="tab:mytab",caption="This is a caption")
The problem is that I only want to display cnt[1] - I am simply
making a table that shows the structure of a dataframe, and I do
not want the variable levels from contents.
class(cnt)
[1] "contents.data.frame"
class(cnt[1])
[1] "list" When I execute your example, it does work, but if I change it to latex(cnt[1]...) then the caption and label do not work because latex.list() is executed. - Mike
What we really need is a latex method for contents. As I usually
include latex(describe(mydata), file='') in an Sweave report I
haven't needed this. If any others need it I'll probably write
latex.contents.data.frame. In the meantime you can take the object
produced by contents( ) and remove the value levels components, then
pass the smaller object to latex().
Frank
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt
University