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

Allow eem_bind to accept a list of existing eem/eemlist objects #64

Open
jpshanno opened this issue Jan 14, 2020 · 1 comment
Open

Allow eem_bind to accept a list of existing eem/eemlist objects #64

jpshanno opened this issue Jan 14, 2020 · 1 comment

Comments

@jpshanno
Copy link
Contributor

Hi I just found eemR today and it's a great package!
I wanted to reading in a subset of files from a directory while testing it out. I ran into a problem after reading in multiple files with lapply I wanted to combine them into a single eemlist object. It looks like eem_bind is meant for the job, but it throws an error when a list of eems is passed in. I traced it back and when a list is passed to eem_bind it wraps it in another list, so the class check fails. Changing eem <- list(...) to eem <- c(...) in the first line of eem_bind takes care of it. The reprex below shows the error and the successful bind with eem <- c(...).
I also wrote an import function for a Horiba, and hope to submit it as a pull request in the future. I have to generalize it a little more because I think the file layout can change depending on the CSV export options selected.

library(eemR)

files <- 
  c(system.file("extdata/cary/scans_day_1/sample1.csv", package = "eemR"),
    system.file("extdata/cary/scans_day_1/sample2.csv", package = "eemR"))

eems <- 
  lapply(files,
         eem_read,
         import_function = "cary")

str(eems, max.level = 1)
#> List of 2
#>  $ :List of 1
#>   ..- attr(*, "class")= chr "eemlist"
#>  $ :List of 1
#>   ..- attr(*, "class")= chr "eemlist"

eem_bind(eems)
#> Error in eem_bind(eems): all(list_classes %in% c("eem", "eemlist")) is not TRUE

eem_bind2 <- 
  function(...) {
    eem <- c(...)
    
    
    list_classes <- unlist(lapply(eem, function(x) {
      class(x)
    }))
    
    stopifnot(all(list_classes %in% c("eem", "eemlist")))
    
    eem <- lapply(eem, eemR:::my_unlist)
    eem <- unlist(eem, recursive = FALSE)
    
    class(eem) <- "eemlist"
    
    return(eem)
  }

eem_bind2(eems)
#>    sample ex_min ex_max em_min em_max is_blank_corrected is_scatter_corrected
#> 1 sample1    220    450    230    600              FALSE                FALSE
#> 2 sample2    220    450    230    600              FALSE                FALSE
#>   is_ife_corrected is_raman_normalized
#> 1            FALSE               FALSE
#> 2            FALSE               FALSE

identical(eem_bind(eems[[1]], eems[[2]]),
          eem_bind2(eems))
#> [1] TRUE

Created on 2020-01-14 by the reprex package (v0.3.0)

@PMassicotte
Copy link
Owner

Hi there. Good catch. I am up for a PR whenever you want 👍

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