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 in sect_title[[2]] : subscript out of bounds #12

Closed
lanndoan opened this issue Jan 22, 2018 · 2 comments
Closed

Error in sect_title[[2]] : subscript out of bounds #12

lanndoan opened this issue Jan 22, 2018 · 2 comments

Comments

@lanndoan
Copy link

I keep getting this error using dfSummary -- and it has happened for all of my data. All of the code worked before...

x was converted to a data frame
Error in sect_title[[2]] : subscript out of bounds
@dcomtois
Copy link
Owner

Please check that you have version 0.8.1. There was an issue with 0.8.0, that might be it.

If you have 0.8.1, please paste the call to dfSummary, with a brief description of your data. Thx

@onesandzeroes
Copy link

I am also having this issue, in summarytools version 0.8.5. In my case, the issue seems to be that I am piping a dataframe through to dfSummary, and because of that the data_info$Dataframe attribute is NULL and doesn't get added to the title. The issue doesn't occur when not using a pipe, as shown in the reprex below.

I think this can be addressed by updating the if ("Dataframe" %in% names(data_info)) check in the print method to check for NULL, I'll send a PR through shortly.

Reprex:

library(tidyverse)
library(summarytools)

data("iris")

summ1 = dfSummary(iris)
data_info1 = attr(summ1, "data_info")
data_info1
#> $Dataframe
#> [1] "iris"
#> 
#> $N.obs
#> [1] 150
print(summ1)
#> Data Frame Summary   
#> iris     
#> N: 150   
#> ------------------------------------------------------------------------------------------------------------------------
#> No   Variable        Stats / Values             Freqs (% of Valid)   Text Graph                       Valid    Missing  
#> ---- --------------- -------------------------- -------------------- -------------------------------- -------- ---------
#> 1    Sepal.Length    mean (sd) : 5.84 (0.83)    35 distinct val.       . . : :                        150      0        
#>      [numeric]       min < med < max :                                 : : : :                        (100%)   (0%)     
#>                      4.3 < 5.8 < 7.9                                   : : : : :                                        
#>                      IQR (CV) : 1.3 (0.14)                             : : : : :                                        
#>                                                                      : : : : : : : :                                    
#> 
#> 2    Sepal.Width     mean (sd) : 3.06 (0.44)    23 distinct val.             :                        150      0        
#>      [numeric]       min < med < max :                                       :                        (100%)   (0%)     
#>                      2 < 3 < 4.4                                           . :                                          
#>                      IQR (CV) : 0.5 (0.14)                               : : : :                                        
#>                                                                      . . : : : : : :                                    
#> 
#> 3    Petal.Length    mean (sd) : 3.76 (1.77)    43 distinct val.     :                                150      0        
#>      [numeric]       min < med < max :                               :         . :                    (100%)   (0%)     
#>                      1 < 4.35 < 6.9                                  :         : : .                                    
#>                      IQR (CV) : 3.5 (0.47)                           : :       : : : .                                  
#>                                                                      : :   . : : : : : .                                
#> 
#> 4    Petal.Width     mean (sd) : 1.2 (0.76)     22 distinct val.     :                                150      0        
#>      [numeric]       min < med < max :                               :                                (100%)   (0%)     
#>                      0.1 < 1.3 < 2.5                                 :       . .   :                                    
#>                      IQR (CV) : 1.5 (0.64)                           :       : :   :   .                                
#>                                                                      : :   : : : . : : :                                
#> 
#> 5    Species         1. setosa                  50 (33.3%)           IIIIIIIIIIIIIIII                 150      0        
#>      [factor]        2. versicolor              50 (33.3%)           IIIIIIIIIIIIIIII                 (100%)   (0%)     
#>                      3. virginica               50 (33.3%)           IIIIIIIIIIIIIIII                                   
#> ------------------------------------------------------------------------------------------------------------------------

summ2 = iris %>%
    select(- Petal.Length) %>%
    dfSummary()
data_info2 = attr(summ2, "data_info")
data_info2
#> $Dataframe
#> NULL
#> 
#> $N.obs
#> [1] 150
print(summ2)
#> Error in sect_title[[2]]: subscript out of bounds

onesandzeroes added a commit to onesandzeroes/summarytools that referenced this issue Jul 2, 2018
Fixes issue dcomtois#12.

If the dataframe used for dfSummary comes from a pipe, `data_info$Dataframe` is `NULL` and `sect_title` doesn't get populated properly. This can be fixed by checking for `NULL`.
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

3 participants