Created
January 31, 2014 21:49
-
-
Save ateucher/8743987 to your computer and use it in GitHub Desktop.
Fix to lsa function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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