Last active
September 20, 2016 04:12
-
-
Save dvanic/77c04a3a3b5cfe6f728f433ec1a92b96 to your computer and use it in GitHub Desktop.
Character to variable and variable to character conversion #R
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
# Variable name to character | |
deparse(substitute(variable)) | |
"variable" | |
# Character to variable | |
eval(as.name("variable")) | |
str(eval(as.name("variable"))) # should work | |
# More complex case - when we're sticking it all into a function | |
outerfunction <- function(resultsdataframe, prefix){ | |
bp <- innerfunction(resultsdataframe, prefix) | |
return(bp) | |
} | |
innerfunction <- function(resultsdataframe, prefix){ | |
# if the resultsdataframe = "EBvsS" i.e. class(resultsdataframe) == "character" | |
# the value (i.e. actual data frame) | |
print(eval(as.name(eval(resultsdataframe)))) | |
# its name | |
print(resultsdataframe) | |
# below if it points directly to data frame - the actual data | |
#print(eval(as.name(substitute(resultsdataframe)))) | |
# can't seem to get it to play nice and return the name | |
} | |
doIget <- outerfunction( resultsdataframe = "lala", prefix = "whatever") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment