sfheaders icon indicating copy to clipboard operation
sfheaders copied to clipboard

Factor id levels get dropped

Open dcooley opened this issue 5 years ago • 0 comments

Originally reported here - https://github.com/SymbolixAU/mapdeck/issues/337#issuecomment-735463808

When using a factor column as an 'id', the levels get dropped

df <- data.frame(
  x = 1:5
  , y = 1:5
  , val = letters[1:5]
  , stringsAsFactors = TRUE
)


sf <- sfheaders::sf_linestring(
  obj = df
  , x = "x"
  , y = "y"
  # , linestring_id = "val"
  , keep = TRUE
)

str( sf$val )
# Factor w/ 5 levels "a","b","c","d",..: 1

sf <- sfheaders::sf_linestring(
    obj = df
    , x = "x"
    , y = "y"
    , linestring_id = "val"
    , keep = TRUE
)

str( sf$val )
# int [1:5] 1 2 3 4 5

dcooley avatar Dec 09 '20 00:12 dcooley