gpt4 book ai didi

R:从 2 个 zip 文件夹中读取 csv

转载 作者:行者123 更新时间:2023-12-04 07:50:29 25 4
gpt4 key购买 nike

我在一些不幸的情况下工作,需要从 2 个 zip 文件夹中读取 csv 文件。我的意思是文件路径看起来像这样://path/folder1.zip/folder2.zip/wanttoread.csv我试着模仿这里发现的这个问题的巧妙工作:Extract certain files from .zip ,但到目前为止还没有运气。具体来说,当我最后运行类似的东西时,我收到一条错误消息

Error in fread(x, sep = ",", header = TRUE, stringsAsFactors = FALSE) : 
embedded nul in string:
接着是一堆编码的废话。
关于如何处理这个问题的任何想法?提前致谢!

最佳答案

这是使用 tempdir() 的方法:

temp<-tempdir(check = TRUE) #Create temporary directory to extract into

unzip("folder1.zip",exdir = temp) #Unzip outer archive to temp directory

unzip(file.path(temp,"folder2.zip"), #Use file.path to generate the path to the inner archive
exdir = file.path(temp,"temp2")) #Extract to a subfolder inside temp
#This covers the case when the outer archive might also have a file named wanttoread.csv

list.files(file.path(temp,"temp2")) #We can see the .csv file is now there
#[1] "wanttoread.csv"

read.csv(file.path(temp,"temp2","wanttoread.csv")) #Read it in
# Var1 Var2
#1 Hello obewanjacobi

关于R:从 2 个 zip 文件夹中读取 csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67012098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com