Reputation: 45
I'm assigning a data frame to a variable name taken from a string. So when I run the code I don't know what the variable name will be. I want to pass that data frame to another function to plot it. How can I pass it to the function without knowing its name?
file_name <- file.choose()
fname <- unlist (strsplit (file_name, "\\", fixed = TRUE))
fname <- fname[length(fname)]
waf_no <- unlist (strsplit (fname, "\\s"))
waf_no <- waf_no[grep(waf_no, pattern="WAF")]
data <- read_WAF_file (file_name)
assign(waf_no, flux_calc(data)) #flux calc() calculates and manipulates the data frame
plot_waf(?)
my plot_waf function is very simple
plot_waf <- function (dataframe) {
library("ggplot2")
qplot(dist,n2o,data=dataframe,shape=treat)
}
Upvotes: 1
Views: 188
Reputation: 24238
The inverse for assign
is get
:
Search by name for an object (
get
) or zero or more objects (mget
).
Therefore, you'll need to run your plot function like this:
plot_waf(get(waf_no))
Upvotes: 1