You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you try to access a non-existent column on a SpatVector using $, an error is thrown. This differs from the default behavior of a data.frame, where NULL is returned. I've noticed this because I typically use is.null(df$column) to check if a column exists on a data frame, and therefore tried to use the same approach for a SpatVector. Personally, I think it'd be nice for the sake of consistency for a SpatVector to behave as a data.frame does in this case. However, there may be reasons to throw an error in this case rather than returning NULL - feel free to close this issue if this isn't how you want a SpatVector to behave.
library(terra)
#> terra 1.7.22v<- vect(system.file("ex/lux.shp", package="terra"))
v$not_a_column#> Error: [$] not_a_column is not a variable name in xv_df<- as.data.frame(v)
v_df$not_a_column#> NULL
If you try to access a non-existent column on a
SpatVector
using$
, an error is thrown. This differs from the default behavior of adata.frame
, whereNULL
is returned. I've noticed this because I typically useis.null(df$column)
to check if a column exists on a data frame, and therefore tried to use the same approach for aSpatVector
. Personally, I think it'd be nice for the sake of consistency for aSpatVector
to behave as adata.frame
does in this case. However, there may be reasons to throw an error in this case rather than returningNULL
- feel free to close this issue if this isn't how you want aSpatVector
to behave.Created on 2023-04-17 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: