R object browser for ESS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.0KB

  1. detectBadName <- function(name)
  2. {
  3. !grepl("^[[:alpha:]]([[:alnum:]]|[_.])*$", name)
  4. }
  5. getType <- function(object)
  6. {
  7. if (is.list(object))
  8. {
  9. paste0("+",
  10. if(is.data.frame(object)) "D"
  11. else if(isS4(object)) "S"
  12. else "L")
  13. } else
  14. {
  15. paste0(" ",
  16. if(is.function(object)) "f"
  17. else if(is.numeric(object)) "n"
  18. else if(is.character(object)) "c"
  19. else if(inherits(object, "formula")) "F"
  20. else if(is.logical(object)) "l")
  21. }
  22. }
  23. listObjects <- function()
  24. {
  25. noms <- ls(envir = .GlobalEnv)
  26. objects <- mget(noms, envir = .GlobalEnv)
  27. types <- lapply(objects, getType)
  28. vars <- lapply(noms, function(nom)
  29. {
  30. if (detectBadName(nom))
  31. {
  32. nom <- gsub("\\n", "\\\\n", nom)
  33. nom <- gsub("\\t", "\\\\t", nom)
  34. nom <- gsub("\\`", "\\\\`", nom)
  35. paste0("`", nom, "`")
  36. } else nom
  37. })
  38. # if R-object-browser-fancy-char ?
  39. noms <- gsub("\\n", "⏎", noms)
  40. noms <- gsub("\\t", "⭾", noms)
  41. noms <- gsub("\\`", "\\\\`", noms)
  42. Map(cat, types, noms, vars, "\n") -> nul
  43. }
  44. listObjects()
  45. objectContent <- function(x)
  46. {
  47. if (is.list(x))
  48. {
  49. noms <- if (is.null(names(x))) 1:length(x) else names(x)
  50. objects <- mget(noms, envir = x)
  51. types <- lapply(objects, get_type)
  52. noms <- gsub("\\n", "⏎", noms)
  53. noms <- gsub("\\t", "⭾", noms)
  54. Map(cat, types, noms, "\n") -> nul
  55. }
  56. }
  57. object_content(irg)
  58. object_content(irg[["data"]])
  59. object_content(irg[["data"]][[1]])
  60. search() "package:zzz"
  61. list_packages <- function()
  62. printdfleft(data.frame(packages = gsub("^package:", "",
  63. Filter(function(x) grepl("^package:", x),
  64. search()))))
  65. list_packages()
  66. objects("package:zzz")
  67. class("package::zzz")
  68. objects("package:dplyr")
  69. detach("package:zzz")
  70. help("package:zzz")
  71. help("zzz::fun")