MomX / Momocs

:dove: Morphometrics using R
http://momx.github.io/Momocs/
51 stars 18 forks source link

stringsAsFactor in data.frame making factors #181

Closed bhive01 closed 6 years ago

bhive01 commented 6 years ago

When converting outputs of Momocs functions back to dataframes for further processing and visualization, I'm getting errors related to factors.

I'm specifically using as_df.PCA to convert PCA results for merging back to my original dataset. This throws an warning because I'm merging a factor with a character vector. It's just a warning, but the reason it's happening is a simple one. data.frame uses stringsAsFactors = TRUE as a default. You could add sAF = FALSE to every instance or, since you are using Tidyverse already, consider using tibble::data_frame() which defaults to FALSE.

I can see this pattern on the following lines: https://github.com/vbonhomme/Momocs/blob/master/R/babel-bridges.R#L263 https://github.com/vbonhomme/Momocs/blob/master/R/babel-bridges.R#L297 https://github.com/vbonhomme/Momocs/blob/b170fe58736e4508464234f139618b9066cadde9/R/babel-bridges.R#L310 https://github.com/vbonhomme/Momocs/blob/master/R/babel-bridges.R#L321

In the last one, this is literally a factor so you may want to keep that one, or explicitly convert it.

vbonhomme commented 6 years ago

You're perfectly right and this has long made me suffer. I'm about to data_frame everything anyway (and remove this bloody .refactor). See #184. and sorry for the delay btw.