Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created January 31, 2014 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateucher/8743987 to your computer and use it in GitHub Desktop.
Save ateucher/8743987 to your computer and use it in GitHub Desktop.
Fix to lsa function
x <- 1:26
y <- LETTERS
z <- data.frame(x,y)
unrowname <- function(x) {
rownames(x) <- NULL
return(x)
}
lsa <- function ()
{
obj_type <- function(x) class(get(x))
foo = data.frame(sapply(ls(envir = .GlobalEnv), obj_type))
foo$object_name = rownames(foo)
names(foo)[1] = "class"
names(foo)[2] = "object"
return(unrowname(foo))
}
lsa()
# class object
# 1 function lsa
# 2 character x ## Character, should be integer
# 3 character y
# 4 data.frame z
lsa2 <- function ()
{
obj_type <- function(x) class(get(x, envir = .GlobalEnv)) # define environment
foo = data.frame(sapply(ls(envir = .GlobalEnv), obj_type))
foo$object_name = rownames(foo)
names(foo)[1] = "class"
names(foo)[2] = "object"
return(unrowname(foo))
}
lsa2()
# class object
# 1 function lsa
# 2 function lsa2
# 3 integer x ## Correctly as integer
# 4 character y
# 5 data.frame z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment