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

Behavior of unlist on nested lists #28

Open
lwaldron opened this issue Feb 24, 2019 · 2 comments
Open

Behavior of unlist on nested lists #28

lwaldron opened this issue Feb 24, 2019 · 2 comments

Comments

@lwaldron
Copy link

Is these differences with base::unlist() intentional? 1) names of vector, 2) behavior on nested lists.

suppressPackageStartupMessages(library(S4Vectors))

# both return numeric, although with different names
base::unlist(list(a=1, b=2:1))
#>  a b1 b2 
#>  1  2  1
BiocGenerics::unlist(SimpleList(a=1, b=2:1))
#> a b b 
#> 1 2 1

# returns numeric
base::unlist(list(a=1, b=list(2:1)))
#>  a b1 b2 
#>  1  2  1
# returns class "base::list" containing an `IntegerList` element
BiocGenerics::unlist(List(a=1, b=List(2:1)))
#> $a
#> [1] 1
#> 
#> $b
#> List of length 1

sessionInfo()
#> R Under development (unstable) (2019-01-26 r76018)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 9 (stretch)
#> 
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib/libopenblasp-r0.2.19.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
#> [8] methods   base     
#> 
#> other attached packages:
#> [1] S4Vectors_0.21.10   BiocGenerics_0.29.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.0      digest_0.6.18   magrittr_1.5    evaluate_0.13  
#>  [5] highr_0.7       stringi_1.3.1   rmarkdown_1.11  tools_3.6.0    
#>  [9] stringr_1.4.0   xfun_0.5        yaml_2.2.0      compiler_3.6.0 
#> [13] htmltools_0.3.6 knitr_1.21

Created on 2019-02-24 by the reprex package (v0.2.1)

@hpages
Copy link
Contributor

hpages commented Mar 5, 2019

The 1st one is intentional (the name mangling preformed by base::unlist() is insane so we got rid of it).

The 2nd one is not. We didn't implement recursive unlisting for List derivatives yet. I'll take care of it.

@LTLA
Copy link
Contributor

LTLA commented Sep 23, 2019

Just encountered this. It seems as if it would be fairly simple to fix with the following prototype code:

# In unlist,List-method:
    if (length(dim(xx[[1L]])) < 2L) {
        if (recursive) { 
            xx <- lapply(xx, unlist, recursive=TRUE, use.names=use.names)
        }
        unlisted_x <- do.call(c, xx)
    } else { 
# ... and so on

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