自定义函数不向环境输出数据?

Self-defined function doesn't output data to environment?

我正在尝试创建一个小函数来帮助从在线托管的 excel 电子表格中读取数据。

read2014 <- function(urlhere, filename){
      url <- urlhere
      destfile <- filename
      curl::curl_download(url, destfile)
      filename <- read_excel(destfile, skip = 14)
}

当我尝试使用这些参数值调用函数时,没有任何反应。

read2014(urlhere = "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2013/04/Beds-Open-Overnight-Web_File-Q1-2014-15-Revised-Nov15-Final-21447.xlsx", filename = "X2014_Q1")

但是,当我在不使用函数的情况下调用正文时,它将电子表格作为数据框毫无问题地输入到环境中。

url <- "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2013/04/Beds-Open-Overnight-Web_File-Q1-2014-15-Revised-Nov15-Final-21447.xlsx"
destfile <- "X2014_Q1.xlsx"
curl::curl_download(url, destfile)
X2014_Q1 <- read_excel(destfile, skip = 14)

我以前从未写过函数,所以我不确定如何解决这个问题。

正如我在评论中提到的,您忘记了分配输出。

object <- read2014(urlhere = "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2013/04/Beds-Open-Overnight-Web_File-Q1-2014-15-Revised-Nov15-Final-21447.xlsx", filename = "X2014_Q1")