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

SpatVector data frame does not support factor types #697

Closed
ozjimbob opened this issue Jul 4, 2022 · 1 comment
Closed

SpatVector data frame does not support factor types #697

ozjimbob opened this issue Jul 4, 2022 · 1 comment

Comments

@ozjimbob
Copy link

ozjimbob commented Jul 4, 2022

The attribute table/data.frame of SpatVector objects, very simply, does not appear to support factor type columns - without any error being returned the columns simply remain char type after attempting to set them as factor,.

f <- system.file("ex/lux.shp", package="terra")
v <- vect(f) 
v$NAME_2 <- factor(v$NAME_2)
is.factor(v$NAME_2)
[1] FALSE

print(v)

class       : SpatVector 
geometry    : polygons 
dimensions  : 12, 6  (geometries, attributes)
extent      : 5.74414, 6.528252, 49.44781, 50.18162  (xmin, xmax, ymin, ymax)
source      : lux.shp
coord. ref. : lon/lat WGS 84 (EPSG:4326) 
names       :  ID_1   NAME_1  ID_2   NAME_2  AREA   POP
type        : <num>    <chr> <num>    <chr> <num> <int>
values      :     1 Diekirch     1 Clervaux   312 18081
                  1 Diekirch     2 Diekirch   218 32543
                  1 Diekirch     3  Redange   259 18664
@rhijmans
Copy link
Member

rhijmans commented Jul 5, 2022

Thanks, that was one of these pending things that I needed a little push for. I now get

library(terra)
#terra 1.5.50
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f) 
v$NAME_2 <- factor(v$NAME_2)
is.factor(v$NAME_2)
#[1] TRUE

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