bind_rows not working within function

I wrote a function that loads in two .Rdata files to the global environment. Then,within the same function, I want to apply bind_rows() to the two data frames I loaded into my global environment. However, this command does not work within my function. See the code below that is inside my function:

#load files and bind into one file
files <- as.list(c(file1, file2)) #file1 and file2 are file paths already defined earlier in the function
lapply(files, load, .GlobalEnv)
combined_files <- dplyr::bind_rows(file1_df, file2_df) #the _df files are in the global env.

The result is the two files are in my global environment, but combined_files is not created.


combined_files <- dplyr::bind_rows(file1_df, file2_df) 

is run within the function, combined_files will only exist within the function's environment and will disappear when the function finishes running. What is being returned by the function? Can you return combined_files and assign that to an object in the global environment?

Thanks! Yes, I resolved the issue by moving the object to the global environment.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.