From 55e29b486a42096b5acb2d30b6ecd96a8102b1f7 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Mon, 7 Oct 2019 04:48:16 +0200 Subject: [PATCH] Show "true" varname --- functions.R | 32 +++++++++++++++++++++----------- notes.org | 3 +++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/functions.R b/functions.R index f29e142..78e3134 100644 --- a/functions.R +++ b/functions.R @@ -1,3 +1,8 @@ +detectBadName <- function(name) +{ + !grepl("^[[:alpha:]]([[:alnum:]]|[_.])*$", name) +} + getType <- function(object) { if (is.list(object)) @@ -20,21 +25,26 @@ getType <- function(object) listObjects <- function() { noms <- ls(envir = .GlobalEnv) - objects <- lapply(noms, get, envir = .GlobalEnv) - types <- lapply(objects, get_type) - - Map(cat, types, noms, "\n") -> nul -} + objects <- mget(noms, envir = .GlobalEnv) + types <- lapply(objects, getType) + vars <- lapply(noms, function(nom) + { + if (detectBadName(nom)) + { + nom <- gsub("\\n", "\\\\n", nom) + nom <- gsub("\\t", "\\\\t", nom) + paste0("`", nom, "`") + } else nom + }) -list_objects() + noms <- gsub("\\n", "⏎", noms) + noms <- gsub("\\t", "⭾", noms) -class(unclass(x)) -> list | other -length(x) -names(x) + Map(cat, types, noms, vars, "\n") -> nul +} -default_limit <- 5 -current_limit <- default_limit +listObjects() objectContent <- function(x) { diff --git a/notes.org b/notes.org index 3637264..c62cc6f 100644 --- a/notes.org +++ b/notes.org @@ -3,6 +3,9 @@ *** TODO Define the format to convey all the needed information | islist | type | pretty name | size ? | canonical name | +lt label varname +l -> +/" " if list +t -> type ** TODO Allow user-defined actions on object at point * Notes