楼主: entryman
1340 2

[实际应用] iterators库的ireadLines()返回的迭代器不能工作于unz()返回的Connection上? [推广有奖]

  • 0关注
  • 1粉丝

大专生

98%

还不是VIP/贵宾

-

威望
0
论坛币
23 个
通用积分
142.0133
学术水平
6 点
热心指数
6 点
信用等级
4 点
经验
1814 点
帖子
51
精华
0
在线时间
84 小时
注册时间
2014-8-1
最后登录
2023-3-5

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
执行如下代码,原本的意愿是从压缩文件中读取大个头的文本文件,考虑到RAM一次只读取一条,保留感兴趣的内容以便后继计算,但是执行nextElem()后只能返回第一行,和直接从文本文件返回的ireadLines是有区别的,这是为什么呢?或者有没有其它方法或库作为顶替的解决方案?
  1. > library(iterators)
  2. > con<-unz(description='daily_VOCS_1994.zip',filename='daily_VOCS_1994.csv')
  3. > it<-ireadLines(con)
  4. > nextElem(it)
  5. [1] "\"State Code\",\"County Code\",\"Site Num\",\"Parameter Code\",\"POC\",\"Latitude\",\"Longitude\",\"Datum\",\"Parameter Name\",\"Sample Duration\",\"Pollutant Standard\",\"Date Local\",\"Units of Measure\",\"Event Type\",\"Observation Count\",\"Observation Percent\",\"Arithmetic Mean\",\"1st Max Value\",\"1st Max Hour\",\"AQI\",\"Method Name\",\"Local Site Name\",\"Address\",\"State Name\",\"County Name\",\"City Name\",\"CBSA Name\",\"Date of Last Change\""
  6. > nextElem(it)
  7. [1] "\"State Code\",\"County Code\",\"Site Num\",\"Parameter Code\",\"POC\",\"Latitude\",\"Longitude\",\"Datum\",\"Parameter Name\",\"Sample Duration\",\"Pollutant Standard\",\"Date Local\",\"Units of Measure\",\"Event Type\",\"Observation Count\",\"Observation Percent\",\"Arithmetic Mean\",\"1st Max Value\",\"1st Max Hour\",\"AQI\",\"Method Name\",\"Local Site Name\",\"Address\",\"State Name\",\"County Name\",\"City Name\",\"CBSA Name\",\"Date of Last Change\""
  8. >
复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:connection Connect Lines ITER READ 解决方案 文本文件 library 压缩文件

沙发
entryman 发表于 2015-6-26 01:58:26 |只看作者 |坛友微信交流群
没空去挖源代码,不能沉了,顶上去~

使用道具

藤椅
entryman 发表于 2015-6-28 15:00:35 |只看作者 |坛友微信交流群
  1. Rconnection attribute_hidden
  2. R_newunz(const char *description, const char *const mode)
  3. {
  4.     Rconnection new;
  5.     new = (Rconnection) malloc(sizeof(struct Rconn));
  6.     if(!new) error(_("allocation of 'unz' connection failed"));
  7.     new->class = (char *) malloc(strlen("unz") + 1);
  8.     if(!new->class) {
  9.         free(new);
  10.         error(_("allocation of 'unz' connection failed"));
  11.     }
  12.     strcpy(new->class, "unz");
  13.     new->description = (char *) malloc(strlen(description) + 1);
  14.     if(!new->description) {
  15.         free(new->class); free(new);
  16.         error(_("allocation of 'unz' connection failed"));
  17.     }
  18.     init_con(new, description, CE_NATIVE, mode);

  19.     new->canseek = TRUE;
  20.     new->open = &unz_open;
  21.     new->close = &unz_close;
  22.     new->vfprintf = &null_vfprintf;
  23.     new->fgetc_internal = &unz_fgetc_internal;
  24.     new->fgetc = &dummy_fgetc;
  25.     new->seek = &null_seek; //好暴力,不支持seek,readLines没法工作,之上的ireadLines也就没法工作了
  26.     new->fflush = &null_fflush;
  27.     new->read = &unz_read;
  28.     new->write = &null_write;
  29.     new->private = (void *) malloc(sizeof(struct unzconn));
  30.     if(!new->private) {
  31.         free(new->description); free(new->class); free(new);
  32.         error(_("allocation of 'unz' connection failed"));
  33.     }
  34.     return new;
  35. }
复制代码

不知道有没什么替代方案,csv文件的压缩率非常的大,几十MB的包解出来得好几GB~

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 09:26