# i made fix analog that copy obj to temp file as csv, give edit it
# and assign with env.
# so, u can edit dataframe as comfortable format in text editor.
# but technically it doesn`t cause a fix func,
# so it doesn`t match the assignment :(
good_fix <- function(x) {
var_name <- substitute(x)
obj <- get(as.character(var_name), envir = parent.frame())
tmp <- tempfile(fileext = ".csv")
write.csv(obj, tmp, row.names = FALSE, fileEncoding = "UTF-8")
system(paste("vim", tmp))
updated_obj <- read.csv(tmp, fileEncoding = "UTF-8", stringsAsFactors = FALSE)
unlink(tmp)
assign(as.character(var_name), updated_obj, envir = parent.frame())
}
# i temporarily change editor for fix to vim
# because the built-in GUI table editor for X11 in R
# is totally cursed and doesn`t support UTF-8
# however, to do this, i had to set obj class as NULL
true_fix <- function(x) {
var_name <- as.character(substitute(x))
obj <- get(var_name, envir = parent.frame())
old_class <- class(obj)
class(obj) <- NULL
assign(var_name, obj, envir = parent.frame())
old_editor <- options(editor = "vim")
on.exit({
options(old_editor)
updated_obj <- get(var_name, envir = parent.frame())
class(updated_obj) <- old_class
assign(var_name, updated_obj, envir = parent.frame())
})
eval(substitute(fix(name), list(name = var_name)), envir = parent.frame())
}
names <- c("Смирнов", "Элрик", "Карамазов", "Красоткин", "Кэрролл", "Цист")
vote <- c("черный", "красный", "красный", "красный", "черный", "черный")
height <- c(165, 155, 178, 161, 171, 180)
my_stats <- data.frame(Names = names, Color = vote, Height = height)
true_fix(my_stats)
my_stats
height_names <- my_stats[my_stats$Height > 170, "Names"]
height_names