如何为Windows上传由R中的文件夹组成的文件夹?我在每个文件夹中上传各种文本文件 [英] How to upload a folder consisting of folders in R, for windows? I am uploading various text files in each folder

查看:36
本文介绍了如何为Windows上传由R中的文件夹组成的文件夹?我在每个文件夹中上传各种文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Windows,如何在R中加载包含文件夹的文件夹?

How to load a folder consisting of folders in R, for windows?

我在每个子文件夹中都有各种文本文件,所有这些文件我都想一次加载.请提出一种便捷的方法.

I have various text files in each sub-folder, all of which I want to load in one-go. Please suggest a convenient and easy method.

谢谢.

推荐答案

我假设上传"是指加载到 R ".有几种方法可以做到这一点,以下是两种.请注意,第一步是拥有完整路径的正确文件列表(或使用适当的wd)

I am assuming that by "upload" you mean "load into R". There are several ways to do this, below are two. Note that the first step is having the correct list of files with full path (or be working in the appropriate wd)

# Get the list of files
#----------------------------#
  folder <- "path/to/files"
  fileList <- dir(folder, recursive=TRUE)  # grep through these, if you are not loading them all

  # use platform appropriate separator
  files <- paste(folder, fileList, sep=.Platform$file.sep)


# Load them in
#----------------------------#
  # Method 1:
  invisible(sapply(files, source, local=TRUE))

  #-- OR --#

  # Method 2:
  sapply(files, function(f) eval(parse(text=f)))

这篇关于如何为Windows上传由R中的文件夹组成的文件夹?我在每个文件夹中上传各种文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆