简体   繁体   English

将函数内的 .rmd 数据文件加载到环境中

[英]Loading .rmd datafile within a function to the environment

I'm new to functions and I would like to load my data with a function.我是函数的新手,我想用函数加载我的数据。 The function appears to be correct but the file does not save as a dataframe to the environment, while this does happen when it's not within the function.该函数似乎是正确的,但该文件没有作为数据帧保存到环境中,而当它不在函数内时确实会发生这种情况。

This is my script:这是我的脚本:

read_testdata <- function(file) {
  Dataset_test <- read_rds(here("foldername", file))
}

read_testdata("filename")

Can someone spot my error?有人能发现我的错误吗?

After some thinking I spotted my problem, the correct code should be this:经过一番思考,我发现了我的问题,正确的代码应该是这样的:

read_testdata <- function(file) {
 read_rds(here("foldername", file))


}

Dataset_test <- read_testdata("filename.rds")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM