I am attempting to write a function that combines data based on a user input.
I've searched around but cannot find anything that seems to help (I am somewhat new to using R).
Running each line separately works great. However, when I wrap them into a used defined function nothing is produced. For example, I have the following data: ASW1_2016, ASW_2017, ASW_2018, CSW_2015, CSW_2017. I want to prompt the user to input a site name "ASW1" and have the function combine all data that contain this name.
#Running these two lines separately works:
Site <- invisible(readline(prompt = "Enter Site Name:"))
assign(Site, rbindlist(mget(apropos(Site), inherits = TRUE))
#Putting these two lines into a function does not produce anything:
CombineData <- function()
{
Site <- invisible(readline(prompt = "Enter Site Name:"))
assign(Site, rbindlist(mget(apropos(Site), inherits = TRUE))
}
CombineData()
After being asked to enter a site name (e.g. ASW1) I expect all data containing this name to be combined and assigned the name provided by the user. However, as stated above, when I run CombineData() and enter the site name following the prompt, nothing happens.