使用函数在文件名集合上重复函数

Using a function to repeat function over a collection of filenames

我要写一篇 to repeat a chunk of code over a collection of file names (names of files present in my working directory) in 。如果可能的话,我还想将每一行的输出保存为全局环境对象。下面给出了我正在尝试做的事情的一般结构。函数名组成。

global_environment_object_1 <- anyfunction("filename and extension").
# Repeat this over a set of filenames in the working directory and save each as a separate 
# global environment object with separate names. 

现实生活中的例子可以是:

sds22 <- get_subdatasets("EVI_2017_June_2.hdf")
sds23 <- get_subdatasets("EVI_2016_June_1.hdf") 

-其中对象名和文件名正在变化,文件总数为48.

提前感谢您的帮助!

尝试使用:

#Get all the filenames
all_files <- list.files(full.names = TRUE)
#Probably to be specific
#all_files <- list.files(patter = "\.hdf$", full.names = TRUE)
#apply get_subdatasets to each one of them
all_data <- lapply(all_files, get_subdatasets)
#Assign name to list output
names(all_data) <- paste0('sds', seq_along(all_data))
#Get the data in global environment
list2env(all_data, .GlobalEnv)