Browse Source

Subset from .GlobalEnv as with any other container

master
Maxime Wack 3 years ago
parent
commit
f61e3abc0e
1 changed files with 10 additions and 12 deletions
  1. +10
    -12
      functions.Rmd

+ 10
- 12
functions.Rmd View File

@@ -52,19 +52,17 @@ Get the fullname of an object given its identifier and fullname of the parent
##' Get the fullname of an object
##' by prepending its parent and indexing by name/position
##' @title Get fullname
##' @param object A string with the name of an object
##' @param identifier An object identifier string
##' @param parent A string with the name of the parent
##' @return The full object name
get_fullname <- function(object, parent)
get_fullname <- function(identifier, parent)
{
if (parent == "")
fullname <- gsub("\"", "`", object)
else if (substr(parent, nchar(parent) - 1, nchar(parent)) == "::")
fullname <- paste0(parent, gsub("\"", "`", object))
if (substr(parent, nchar(parent) - 1, nchar(parent)) == "::") # If part of a package
fullname <- paste0(parent, gsub("\"", "`", identifier)) # replace quotes with backticks and prepend the package
else
fullname <- paste0(parent, "[[", object, "]]")
fullname <- paste0(parent, "[[", identifier, "]]") # else index the parent by name/position with double brackets

tryCatch(get_object(fullname),
tryCatch(get_object(fullname), # If the object is not exported, use three colons
error = function(e) fullname <<- gsub("::", ":::", fullname))

fullname
@@ -259,12 +257,12 @@ list_environments <- function()
##' @title List environment contents
##' @name Name of the environment as character
##' @return A character vector of objects in the environment
list_environment_contents <- function(env)
list_searchlist_contents <- function(env)
{
if (env == ".GlobalEnv")
parent = ""
if (substring(env, 1, 8) == "package:")
parent <- paste0(substring(env, 9), "::")
else
parent = paste0(substring(env, 9), "::")
parent <- env

objects <- paste0("\"", objects(env), "\"")



Loading…
Cancel
Save