如何在R中读取/写入外部驱动器

时间:2022-02-11 23:12:22

I have an external drive that I want to read and write .txt files to and from. Is there any way I can do this without having to change setwd() to the desired location? For example my external drive's location is: /Volumes/ExtDrive/Folder1

我有一个外部驱动器,我想读取和写入.txt文件。有没有办法我可以做到这一点,而无需将setwd()更改为所需的位置?例如,我的外部驱动器的位置是:/ Volumes / ExtDrive / Folder1

Can I specify desired output location in write.table()?

我可以在write.table()中指定所需的输出位置吗?

1 个解决方案

#1


1  

You can do this by simply specifying the full file path (by creating an object or pasting the full path) in each of your read write calls. e.g.,

您可以通过在每个读写调用中指定完整文件路径(通过创建对象或粘贴完整路径)来完成此操作。例如。,

#set the data file
data <- read.table(file = "/Volumes/ExtDrive/Folder1/data.txt", ...)
#specify the file path for the output file
fpout <- "/Volumes/ExtDrive/Folder1/"
#output the datafile
write.table(x = "data.txt", file = fpout , ...)

#1


1  

You can do this by simply specifying the full file path (by creating an object or pasting the full path) in each of your read write calls. e.g.,

您可以通过在每个读写调用中指定完整文件路径(通过创建对象或粘贴完整路径)来完成此操作。例如。,

#set the data file
data <- read.table(file = "/Volumes/ExtDrive/Folder1/data.txt", ...)
#specify the file path for the output file
fpout <- "/Volumes/ExtDrive/Folder1/"
#output the datafile
write.table(x = "data.txt", file = fpout , ...)