R 如何阻止lapply打印到控制台?

R 如何阻止lapply打印到控制台?,r,console,apply,R,Console,Apply,我将一组shapefile读入R,并使用lappy在一组文件中运行它。现在,代码运行良好,但它会将大量信息打印到控制台中。我正试图摆脱它,使控制台更干净 load_shapefiles <- function(file_name){ #grabs the last two digits of the year for the current file partial_year <- str_sub(file_name, start = 9, end = 10) #read in fi

我将一组shapefile读入R,并使用
lappy
在一组文件中运行它。现在,代码运行良好,但它会将大量信息打印到控制台中。我正试图摆脱它,使控制台更干净

load_shapefiles <- function(file_name){
#grabs the last two digits of the year for the current file
partial_year <- str_sub(file_name, start = 9, end = 10)
#read in files
st_read(dsn = sprintf("data/%s", file_name), layer = sprintf("Census_sum_%s", partial_year))
}

#apply the loading function across a list of file names
list_data <- lapply(list_filenames, function(x) load_shapefiles(x))
load\u shapefile使用
capture。输出(load\u shapefile(x))
不可见(load\u shapefile(x))
不可见的地方工作

感谢鲁伊·巴拉达斯的回答


编辑:
st_read
有一个名为
quiet
的参数,该参数确定它是否将打印有关正在读取的文件的信息。将
quiet
设置为TRUE时,无需在
capture.output
invisible

中包装函数,因为打印这些消息的正是此函数,所以可能
不可见(load_shapefile(x))
。或者
capture.output
而不是
invisible
capture.output
工作。出于某种原因,
不可见
没有这样做。谢谢你的帮助!很高兴这有帮助。向上投票,可能对其他人有用,这是这样做的主要目的。