Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memisc with data.table #3

Closed
ghost opened this issue Jan 20, 2016 · 1 comment
Closed

memisc with data.table #3

ghost opened this issue Jan 20, 2016 · 1 comment
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Jan 20, 2016

Since I am often working with surveys the memisc library looks very promising. I always work with data.table and there seems to be an issue however.

When I generate a codebook with memisc on a data.table, there is the following issue: when I type the name of the object (say, mtcars) an error is thrown, see code below.

    library(memisc)
    library(data.table)

    data(mtcars)
    setDT(mtcars, keep.rownames=  T)
    mtcars = within(mtcars, {

      description(vs) = "whatever"
      description(am) = "something unclear"
      description(carb) = "something different"
      wording(vs) = "this is going to be a long comment"

      labels(vs) = c(
        "many" = 1,
        "not so many" = 0
      )

      labels(carb) = c(
        "one" = 1,
        "two" = 2,
        "three" = 3
      )

      missing.values(carb) = c(4,6, 8)

    })

    codebook(mtcars) %>% show_html

    # annotation(mtcars) = "my long story"

    # if data.frame = error and annotation(mtcars) = "....text...." then message "Error in if (nzchar(nm.i)) { : argument is of length zero"
    # annotation(mtcars)

    # if data.table: throws error "Error in format.item(char.trunc(col), justify = justify, ...) : 
    # unused argument (justify = justify)
    mtcars


    > sessionInfo()
    R version 3.2.3 (2015-12-10)
    Platform: x86_64-pc-linux-gnu (64-bit)
    Running under: Ubuntu 15.04

    locale:
      [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=nl_NL.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
    [10] LC_TELEPHONE=C             LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       

    attached base packages:
      [1] grid      stats     graphics  grDevices utils     datasets  methods   base     

    other attached packages:
      [1] Hmisc_3.17-0      ggplot2_2.0.0     Formula_1.2-1     survival_2.38-3   magrittr_1.5      DescTools_0.99.15 manipulate_1.0.1  memisc_0.99.3     MASS_7.3-44       lattice_0.20-33   data.table_1.9.7 

    loaded via a namespace (and not attached):
      [1] Rcpp_0.12.3         nloptr_1.0.4        RColorBrewer_1.1-2  plyr_1.8.3          tools_3.2.3         rpart_4.1-10        boot_1.3-17         lme4_1.1-9          nlme_3.1-122        gtable_0.1.2        mgcv_1.8-7          Matrix_1.2-2       
    [13] parallel_3.2.3      mvtnorm_1.0-3       SparseM_1.7         proto_0.3-10        gridExtra_2.0.0     cluster_2.0.3       MatrixModels_0.4-1  nnet_7.3-11         foreign_0.8-66      latticeExtra_0.6-26 minqa_1.2.4         car_2.0-25         
    [25] scales_0.3.0        splines_3.2.3       rsconnect_0.4.1.11  pbkrtest_0.4-2      colorspace_1.2-6    quantreg_5.19       acepack_1.3-3.3     munsell_0.4.2       chron_2.3-47       
@melff
Copy link
Owner

melff commented Jan 24, 2016

You are using annotation etc. in a way they are not intended:

  • annotation etc. are supposed only to work with objects of class "item" which are expected to be in a "data.set" object rather than a "data.frame" or "data.table" object.
  • There is no support for "data.table" objects yet.

To get what you apparently want, try:

library(memisc)
library(data.table)

data(mtcars)
## This is necessary to get things working ...
mtcars <- as.data.set(mtcars)

mtcars <- within(mtcars, {

  description(vs) <- "whatever"
  description(am) <- "something unclear"
  description(carb) <- "something different"
  wording(vs) <- "this is going to be a long comment"

  labels(vs) <- c(
    "many" = 1,
    "not so many" = 0
  )

  labels(carb) <- c(
    "one" = 1,
    "two" = 2,
    "three" = 3
  )

  missing.values(carb) <- c(4,6, 8)
})

codebook(mtcars) 
annotation(mtcars) <- "my long story"
annotation(mtcars)
mtcars

## To get a data frame, use
# as.data.frame(mtcars)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant