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

Error: cogdf must be a cognostics object - call as_cognostics() to cast it as such. #102

Open
stefvanbuuren opened this issue Nov 26, 2020 · 4 comments

Comments

@stefvanbuuren
Copy link

The following code was previously - in May 2020 - working (see #25):

library(trelliscopejs)
library(ggplot2)
library(dplyr)
library(tidyr)

my_order <- c("subcompact", "compact", "midsize",
              "minivan", "pickup", "suv", "2seater")

# Ryan's solution: https://github.com/hafen/trelliscopejs/issues/25
mpg %>%
  mutate(class = factor(class, levels = my_order),
         class_index = as.integer(class)) %>%
  group_by(class, class_index) %>%
  nest() %>%
  mutate(panel = map_plot(data,
                          ~ ggplot(data = .x, aes(displ, hwy)) +
                            geom_point() +
                            xlab("Engine displacement, litres") +
                            ylab("Highway miles per gallon") +
                            xlim(1, 7) + ylim(10, 60) +
                            theme_light())) %>%
  trelliscope(name = "MPG custom panel order",
              state = list(sort = list(sort_spec("class_index"))),
              nrow = 1, ncol = 1,
              path = "docs/mpg-custom")

In R 4.0.3 and trelliscopejs 0.2.5 it throws

58% 7/12 eta: 1sError: cogdf must be a cognostics object - call as_cognostics() to cast it as such.
In addition: Warning message:
`filter_()` is deprecated as of dplyr 0.7.0.
Please use `filter()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated. 

The call writes contents into the appfiles directory, but produces no index.html files or lib directory.

Could this be related to #91? Any work-arounds?

@stefvanbuuren
Copy link
Author

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] tidyr_1.1.2         dplyr_1.0.2         ggplot2_3.3.2       trelliscopejs_0.2.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5              later_1.1.0.1           pillar_1.4.6            compiler_4.0.3          prettyunits_1.1.1       base64enc_0.1-3         tools_4.0.3            
 [8] progress_1.2.2          digest_0.6.27           mclust_5.4.6            jsonlite_1.7.1          lifecycle_0.2.0         tibble_3.0.4            gtable_0.3.0           
[15] checkmate_2.0.0         pkgconfig_2.0.3         rlang_0.4.9             shiny_1.5.0             rstudioapi_0.13         xfun_0.19               fastmap_1.0.1          
[22] withr_2.3.0             knitr_1.30              generics_0.1.0          vctrs_0.3.5             DistributionUtils_0.6-0 hms_0.5.3               grid_4.0.3             
[29] webshot_0.5.2           tidyselect_1.1.0        glue_1.4.2              R6_2.5.0                farver_2.0.3            purrr_0.3.4             magrittr_2.0.1         
[36] promises_1.1.1          scales_1.1.1            autocogs_0.1.3          backports_1.2.0         ellipsis_0.3.1          htmltools_0.5.0         xtable_1.8-4           
[43] mime_0.9                colorspace_2.0-0        httpuv_1.5.4            labeling_0.4.2          munsell_0.5.0           crayon_1.3.4.9000  

@stefvanbuuren
Copy link
Author

 traceback()
6: stop(paste(strwrap(paste(...), exdent = 7), collapse = "\n"), 
       call. = FALSE)
5: stop_nice("cogdf must be a cognostics object -", "call as_cognostics() to cast it as such.")
4: write_display_obj(cog_df, panel_example = panels[[1]], panel_img_col = panel_img_col, 
       base_path = params$path, id = params$id, name = params$name, 
       group = params$group, desc = desc, height = height, width = width, 
       md_desc = md_desc, state = params$state, jsonp = params$jsonp, 
       split_sig = params$split_sig, self_contained = params$self_contained, 
       thumb = params$thumb, pb = pb)
3: trelliscope.data.frame(., name = "MPG custom panel order", state = list(sort = list(sort_spec("class_index"))), 
       nrow = 1, ncol = 1, path = "docs/mpg-custom")
2: trelliscope(., name = "MPG custom panel order", state = list(sort = list(sort_spec("class_index"))), 
       nrow = 1, ncol = 1, path = "docs/mpg-custom")
1: mpg %>% mutate(class = factor(class, levels = my_order), class_index = as.integer(class)) %>% 
       group_by(class, class_index) %>% nest() %>% mutate(panel = map_plot(data, 
       ~ggplot(data = .x, aes(displ, hwy)) + geom_point() + xlab("Engine displacement, litres") + 
           ylab("Highway miles per gallon") + xlim(1, 7) + ylim(10, 
           60) + theme_light())) %>% trelliscope(name = "MPG custom panel order", 
       state = list(sort = list(sort_spec("class_index"))), nrow = 1, 
       ncol = 1, path = "docs/mpg-custom")

@hafen
Copy link
Owner

hafen commented Dec 2, 2020

Can you try this and see if it works:

mpg %>%
  mutate(class = factor(class, levels = my_order),
         class_index = as.integer(class)) %>%
  group_by(class, class_index) %>%
  nest() %>%
  mutate(panel = map_plot(data,
                          ~ ggplot(data = .x, aes(displ, hwy)) +
                            geom_point() +
                            xlab("Engine displacement, litres") +
                            ylab("Highway miles per gallon") +
                            xlim(1, 7) + ylim(10, 60) +
                            theme_light())) %>%
  ungroup() %>%
  trelliscope(name = "MPG custom panel order",
              state = list(sort = list(sort_spec("class_index"))),
              nrow = 1, ncol = 1,
              path = "docs/mpg-custom")

Note the only difference is the ungroup(). This should not be necessary so I'll introduce a fix for it. In the mean time, if the ungroup gives you the desired result, that will work for now.

@stefvanbuuren
Copy link
Author

Ryan, that's great. Adding ungroup() %>% prior to trelliscope() solves the problem, both in the basic mpg example as well as in my production plots.

Thanks a lot.

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

No branches or pull requests

2 participants