rbchan / unmarked

R package for hierarchical models in ecological research
https://rbchan.github.io/unmarked/
36 stars 25 forks source link

allow import of dataframes with multiple classes #111

Closed bakerccm closed 6 years ago

bakerccm commented 6 years ago

A minor suggestion that might help reduce data import issues. Dataframes that have multiple classes cause unmarkedFrameOccu to fail if data.frame is not the first named class -- see example below. Using as.data.frame() solves the issue, but it could also be avoided if unmarkedFrameOccu checked the class of the object differently. The documentation for unmarkedFrameOccu just says that the input should be a dataframe, which fake.df in the example is, so it's not immediately obvious why it doesn't work without as.data.frame().

library("dplyr") library("unmarked") fake.df <- data.frame(replicate.1 = 1:2, replicate.2 = 1:2) %>% as.tibble() class(fake.df) # [1] "tbl_df" "tbl" "data.frame" fake.umf <- unmarkedFrameOccu(y = fake.df, obsCov=list(reads=fake.df)) # gives error fake.umf <- unmarkedFrameOccu(y = fake.df, obsCov=list(reads=as.data.frame(fake.df))) # works OK

rbchan commented 6 years ago

I'm not too keen on trying to accommodate 'tidyverse' stuff, but feel free to send a (simple) patch.