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.

82 lines
1.8KB

  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. paste0("`", nom, "`")
  35. } else nom
  36. })
  37. noms <- gsub("\\n", "⏎", noms)
  38. noms <- gsub("\\t", "⭾", noms)
  39. Map(cat, types, noms, vars, "\n") -> nul
  40. }
  41. listObjects()
  42. objectContent <- function(x)
  43. {
  44. if (is.list(x))
  45. {
  46. noms <- if (is.null(names(x))) 1:length(x)
  47. else names(x)
  48. list <- ifelse(lapply(x, is.list), "*", "")
  49. printdfleft(data.frame(list = list,
  50. noms = noms))
  51. }
  52. }
  53. object_content(irg)
  54. object_content(irg[["data"]])
  55. object_content(irg[["data"]][[1]])
  56. search() "package:zzz"
  57. list_packages <- function()
  58. printdfleft(data.frame(packages = gsub("^package:", "",
  59. Filter(function(x) grepl("^package:", x),
  60. search()))))
  61. list_packages()
  62. objects("package:zzz")
  63. class("package::zzz")
  64. objects("package:dplyr")
  65. detach("package:zzz")
  66. help("package:zzz")
  67. help("zzz::fun")