I don't know how to describe this question in the title very well. As an arbitrary example, I have created a function that creates a data frame of a vector, and its argument is supposed to be the column name of the new dataframe. However, when I run the function it returns "string" as the dataframe colname, instead of "character_string" as the colname. Pretty straightforward and I know whats happening, it's just I can't seem to find the right R function to help me achieve this.
func <- function(string){
vec <- 1:5
df <- data.frame(string = vec)
return(df)
}
df <- func("character_string")
df
string
1 1
2 2
3 3
4 4
5 5
Here is another example,
func2 <- function(statement){
df <- data.frame(col1 = 1:5, col2 = 5:10)
flag <- FALSE
if(statement){
flag <- TRUE
}
return(flag)
}
func2("df[1,1] == 1")
This will obviously return an error, I need the func2 to return the flag as TRUE. This may seem like a very weird way of doing something, but I'm just trying to wrap my head around this concept for some other application.