natverse / fafbseg

Support functions for analysis of Drosophila connectomes especially the FAFB-FlyWire whole brain
https://natverse.org/fafbseg/
GNU General Public License v3.0
6 stars 4 forks source link

ngl_add_colour need to fix df to list #97

Closed SiqiFang closed 3 years ago

SiqiFang commented 3 years ago

level is introduced for dfs with colour information is recorded in characters when turning into named list, making its name unrecognisable. See the second example given.

jefferis commented 3 years ago

Thanks, @SiqiFang. Do you mean the colour comes in as a factor. If so perhaps this is because you are on R 3.6.x. We can try to convert on input.

jefferis commented 3 years ago

@SiqiFang noted the following in direct conversation:

The error came from the dataframe colourdf. basically what happened is that inside the function ngl_add_colour(), colour information given in dataframes are then converted to named lists by as.list(setNames(colours[[2]], as.character(colours[[1]]))), after which it is tested if this is a vector. For normal examples, this works fine. However when the colour information is given in terms of characters, e.g. red, green and blue, the df converted to list is no longer a vector, hence the error.
I do currently have R 3.6.x which might be causing the problem.

Bottom line, this appears to be an issue with handling of factors – the default for stringsAsFactors changed in R4.0.