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

NULL when printing egor object #80

Closed
raffaelevacca opened this issue Dec 2, 2022 · 7 comments · Fixed by #81
Closed

NULL when printing egor object #80

raffaelevacca opened this issue Dec 2, 2022 · 7 comments · Fixed by #81
Assignees

Comments

@raffaelevacca
Copy link
Collaborator

When printing an egor object no data head is displayed, just NULL. This happens even though the egor object can be correctly analyzed. It seems to happen for any egor object, including those created in the main egor vignette.

Reproducible:

library(egor)

# Create egor
e1 <- egor(alters = alters32,
           egos = egos32,
           aaties = aaties32,
           ID.vars = list(
             ego = ".EGOID",
             alter = ".ALTID",
             source = ".SRCID",
             target = ".TGTID"))

# Prints NULL
e1

# The object is created correctly and can be analyzed
summary(e1)

# Filtering also prints NULL
e1[e1$ego$age.years > 35, ]
e1 %>% 
  filter(income > 36000)

Print output in my console:
Screen Shot 2022-12-02 at 4 34 30 PM

Session info:

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/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  
[7] base     

other attached packages:
[1] egor_1.22.5  tibble_3.1.8 dplyr_1.0.9 

loaded via a namespace (and not attached):
 [1] pillar_1.8.1     compiler_4.1.2   tools_4.1.2     
 [4] digest_0.6.29    evaluate_0.16    lifecycle_1.0.1 
 [7] lattice_0.20-45  pkgconfig_2.0.3  rlang_1.0.4     
[10] igraph_1.3.4     Matrix_1.4-0     tidygraph_1.2.2 
[13] DBI_1.1.1        cli_3.3.0        rstudioapi_0.13 
[16] yaml_2.2.1       xfun_0.32        fastmap_1.1.0   
[19] knitr_1.40       srvyr_1.1.1      generics_0.1.3  
[22] vctrs_0.4.1      mitools_2.4      grid_4.1.2      
[25] tidyselect_1.1.2 glue_1.6.2       R6_2.5.1        
[28] fansi_0.5.0      survival_3.2-13  rmarkdown_2.16  
[31] bookdown_0.28    purrr_0.3.4      tidyr_1.2.0     
[34] magrittr_2.0.3   ellipsis_0.3.2   htmltools_0.5.2 
[37] splines_4.1.2    assertthat_0.2.1 utf8_1.2.2      
[40] survey_4.1-1     crayon_1.4.2    
@mbojan
Copy link
Collaborator

mbojan commented Dec 4, 2022

As far as I can tell print.egor() uses a deprecated way of printing tibbles. I'm looking into fixing it.

@mbojan mbojan self-assigned this Dec 4, 2022
mbojan added a commit that referenced this issue Dec 4, 2022
Printing 'egor' objects now simply calls pillar:::print.tbl_df() for
each of the elements of the objects. In order to skip the "header" which
we print in our own way (data level plus the "active" adjective if
applicable) it is necessary to add the method for tbl_sum() as printing
of tibbles cannot be controled with arguments nor options.

Package 'pillar' is now imported.

Upgrade RoxygenNote in DESCRIPTION.

References #80.
@mbojan mbojan linked a pull request Dec 4, 2022 that will close this issue
mbojan added a commit that referenced this issue Dec 4, 2022
@mbojan mbojan closed this as completed in #81 Dec 4, 2022
@raffaelevacca
Copy link
Collaborator Author

Thank you @mbojan! Printing works well now.

@raffaelevacca
Copy link
Collaborator Author

@mbojan the ANSI code style string for coloring "active" in green in print.egor() output is giving me problems when rendering to pdf an Rmarkdown with egor print output. It's the \033[32m and \033[39m part in this line:

egor/R/egor.R

Line 337 in e5980a5

" (\033[32mactive\033[39m): ",

When rendering Rmarkdown to pdf for some reason those strings create an invalid character that Latex can't render to pdf regardless of the latex engine (pdflatex, xelatex or lualatex). The result is the Rmd can't be rendered to pdf due to invalid character error (Text line contains an invalid character). It's similar to the issue described here, except no latex engine works: https://bookdown.org/yihui/rmarkdown-cookbook/latex-unicode.html

Can I remove that part (\033[32m and \033[39m) i.e. remove the green coloring from print.egor() output? Or do you want to look into that first? Note there is no green coloring of "active" in the tidygraph print output.

Reproducible:

---
title: "Test"
output: 
  pdf_document:
    latex_engine: xelatex
date: '2022-12-05'
editor_options: 
  chunk_output_type: console
---

```{r}
library(tidyverse)
library(egor)

# Create egor
e1 <- egor(alters = alters32,
           egos = egos32,
           aaties = aaties32,
           ID.vars = list(
             ego = ".EGOID",
             alter = ".ALTID",
             source = ".SRCID",
             target = ".TGTID"))

# Print egor
e1

# Note no green coloring in tidygraph print output
library(tidygraph)
as_igraph(e1) |> 
  pluck(1) |> 
  as_tbl_graph()

@raffaelevacca raffaelevacca reopened this Dec 5, 2022
@mbojan
Copy link
Collaborator

mbojan commented Dec 5, 2022 via email

@raffaelevacca
Copy link
Collaborator Author

raffaelevacca commented Dec 5, 2022

@tilltnet what do you think? Do you see any other solution (other than getting rid of it) to avoid that error when rendering to pdf?

Also note that the \033 character is disregarded and green coloring is not rendered in htlm, see for example the egor vignette: https://cran.r-project.org/web/packages/egor/vignettes/using_egor.html#base-r

Screen Shot 2022-12-05 at 9 51 17 PM

@tilltnet
Copy link
Owner

tilltnet commented Dec 6, 2022

If we want to keep the coloring, the cli package could be used for colored print output. crayon is deprecated but works.

@mbojan Yes, please go ahead and remove the coloring or feel free to look into how to do it with cli or crayon. Thank you so much either way for looking into this!

raffaelevacca added a commit that referenced this issue Dec 6, 2022
Removed (temporarily?) to allow pdf rendering from Rmd. Code coloring string causes "invalid character" error when compiling latex doc to pdf. See #80
@raffaelevacca
Copy link
Collaborator Author

I removed the coloring string for now (b6155ca), it's easy to put it back in if needed, or we can look into other coloring solutions. That should probably be a separate issue though, so I'm closing this issue. Pdf rendering works now, thank you @mbojan and @tilltnet.

@raffaelevacca raffaelevacca self-assigned this Dec 6, 2022
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

Successfully merging a pull request may close this issue.

3 participants