I was editing a script while Posit Assistant (Claude via API key) worked on it, and the R process became unresponsive. R was becoming unresponsive frequently due to a Shiny app issue I was diagnosing. It's common for R to become unresponsive and RStudio offering to terminate R when running a Shiny app in quick sucession. While I was editing the file, Posit Assistant added changes to the same file, too. I was pressing cmd+Z and shift+Z to undo/redo some changes, until RStudio threw an error about being unable to save the file. Meanwhile, the R console was waiting for some tests that Posit Assistant requested. I tried to save the file and couldn't, so I stopped the R process, tried to save again, and this being a common occurence (RStudio throwing errors about not saving files) I copied the script then restarted the whole R Session, and when RStudio restarted, a different project was opened. That was the first "uh oh" moment. So I go and check, and voilá, no files in my project, not even a .RProject file, only .Rhistory showing the last commands the AI tried to run, which were:
runApp()
runApp()
runApp()
runApp()
local({
library(arrow); library(sf); library(dplyr)
t0 <- Sys.time()
d <- read_parquet("datos/proyectos_subdere_geo.parquet")
t1 <- Sys.time()
d <- d |> mutate(geometry = st_as_sfc(geometry)) |> st_as_sf()
t2 <- Sys.time()
message("lectura: ", round(t1 - t0, 2), " s; sfc: ", round(t2 - t1, 2), " s")
message("filas: ", nrow(d), "; columnas: ", ncol(d))
message("comuna: ", sum(d$estado_geo == "comuna", na.rm = TRUE))
print(sapply(sf::st_drop_geometry(d), \(x) class(x)[1]))
t3 <- Sys.time()
gj <- geojsonsf::sf_geojson(d)
t4 <- Sys.time()
message("geojson completo: ", round(nchar(gj) / 1e6, 1), " MB en ", round(t4 - t3, 2), " s")
cols <- c("id","nombre","inversion"="APORTE_SUBDERE_INICIAL","año","programa","nombre_comuna","nombre_region","sp_superpuesto")
gj2 <- geojsonsf::sf_geojson(d |> select(any_of(cols)))
message("geojson columnas mínimas: ", round(nchar(gj2) / 1e6, 1), " MB")
message("geometrías vacías/NA: ", sum(st_is_empty(d)))
print(table(st_geometry_type(d)))
})
local({
library(arrow); library(geoarrow); library(sf); library(dplyr)
t0 <- Sys.time()
d <- read_parquet("datos/proyectos_subdere_geo.parquet") |>
mutate(geometry = st_as_sfc(geometry)) |> st_as_sf()
message("lectura + sfc: ", round(difftime(Sys.time(), t0, units = "secs"), 2), " s")
message("filas: ", nrow(d), "; columnas: ", ncol(d))
message("comuna: ", sum(d$estado_geo == "comuna", na.rm = TRUE))
print(sapply(st_drop_geometry(d), \(x) class(x)[1]))
t3 <- Sys.time()
gj <- geojsonsf::sf_geojson(d)
message("geojson completo: ", round(sum(nchar(gj)) / 1e6, 1), " MB en ",
round(difftime(Sys.time(), t3, units = "secs"), 2), " s")
cols <- c("id","nombre","APORTE_SUBDERE_INICIAL","año","programa","nombre_comuna","nombre_region","sp_superpuesto")
gj2 <- geojsonsf::sf_geojson(d |> select(any_of(cols)))
message("geojson columnas mínimas: ", round(sum(nchar(gj2)) / 1e6, 1), " MB")
message("geometrías vacías: ", sum(st_is_empty(d)))
print(table(st_geometry_type(d)))
print(sort(sapply(st_drop_geometry(d), \(x) sum(nchar(as.character(x)), na.rm = TRUE)) / 1e6, decreasing = TRUE)[1:6])
})
Nothing there aims for AI's fault deleting files. This is probable a read/wrote issue with RStudio under dire conditions. I have all backed up on Git, so this made me lose very little work, but it's really concerning that my whole project can just simply disappear after R gets frozen.