JosiahParry / sfdep

A tidy interface for spatial dependence
https://sfdep.josiahparry.com/
GNU General Public License v3.0
121 stars 5 forks source link

Error with spacetime due to "." at start of of data labels #49

Closed rpkamakura closed 3 months ago

rpkamakura commented 4 months ago

I am using package version 0.2.4.

I am trying to create a simple spacetime object but I am getting an error from cli that says:

Error in `fun(..., .envir = .envir)`:
! Invalid cli literal: `{.data_l...}` starts with a dot.
i Interpreted literals must not start with a dot in cli >= 3.4.0.
i `{}` expressions starting with a dot are now only used for cli styles.
i To avoid this error, put a space character after the starting `{` or use parentheses: `{(.data_l...)}`.
---
Backtrace:
 1. sfdep::spacetime(D4_dat_hspt, geo_f, "TARGET_F_1", "Year")
 2. sfdep::new_spacetime(.data, .geometry, .loc_col, .time_col, active = active)
 3. sfdep::validate_spacetime(.data, .geometry, .loc_col, .time_col)
 4. cli::cli_abort(c("Differing class types for {.var .loc_col}.", ...
 5. cli:::vcapply(message, format_inline, .envir = .envir)
 6. base::vapply(X, FUN, FUN.VALUE = character(1), ..., USE.NAMES = USE.NAMES)
 7. local FUN(X[[i]], ...)
 8. cli::cli_fmt(fun(..., .envir = .envir), collapse = collapse, strip_newline = TRUE)
 9. cli:::cli__rec(expr)
10. local fun(..., .envir = .envir)
11. cli:::cli__message("inline_text", list(text = glue_cmd(..., .envir = .envir, ...
12. "id" %in% names(args)
13. cli:::glue_cmd(..., .envir = .envir, .call = sys.call(), .trim = FALSE)
14. cli:::glue(str, .envir = .envir, .transformer = transformer, .cli = TRUE, ...
15. (function (expr) ...
16. .transformer(expr, .envir) %||% character()
17. local .transformer(expr, .envir)
18. cli:::glue(text, .envir = envir, .transformer = sys.function(), .cli = TRUE)
19. (function (expr) ...
20. .transformer(expr, .envir) %||% character()
21. local .transformer(expr, .envir)
22. cli:::throw(cli_error(call. = caller, "Invalid cli literal: {.code {{{abbrev(code, 10)}}}} starts with a dot.", ...

Here is the code I ran:

#get the data for NDVI
D4_Dat_nz <- read.csv("../01Data/AvgNDVI_gridDat_wZones.csv")
D4_dat_hspt <- D4_Dat_nz[,c("TARGET_F_1", "Year", "AvgNDVI", "Date")]
names(D4_dat_hspt)[names(D4_dat_hspt) == "AvgNDVI"] <- "value" 

#get the locations
GridLocs <- st_read("../01Data/Lvl1_grids/SegmentCanopies_FullWest_wZone_wDispl.shp")
geo <- GridLocs[,-(1:3)]
geo <- geo[,-(2:10)]

#make sure the two line up
pxls <- unique(D4_dat_hspt$TARGET_F_1)
pxls2 <- unique(geo$TARGET_F_1)

geo_f <- geo[geo$TARGET_F_1 %in% pxls,]
geo_f <- st_zm(geo_f)
D4_dat_hspt <- D4_dat_hspt[D4_dat_hspt$TARGET_F_1 %in% pxls2,]

#create your spacetime object
stObj <- spacetime( D4_dat_hspt, geo_f, "TARGET_F_1", "Year")
JosiahParry commented 4 months ago

Hmmm! It looks like a recent version of cli just got pushed that breaks the formatting that we use. In the meantime can you downgrade cli to a version that is less than 3.4?

JosiahParry commented 4 months ago

Oh hm. Actually, I cannot reproduce this. Can you update {cli}?

rpkamakura commented 4 months ago

AvgNDVI_gridDat_wZones.csv SegmentCanopies_FullWest_wZone_wDispl.zip

I am running cli version 3.6.2, which I think is the most recent, but I uninstalled and re-installed it and now the example code you all wrote works! Unfortunately, the example I have does not work. I will update this error note with the code I ran and have added the files I use as well