[問題] 錯誤訊息不知哪裡出錯

看板R_Language作者 (願意感動就是一種享受)時間10年前 (2015/08/29 09:11), 編輯推噓0(0010)
留言10則, 3人參與, 最新討論串1/1
我嘗試抓 web of science的資料,但是出現錯誤訊息,不曉得哪裡出問題? 謝謝 ################## wosurl<-"http://apps.webofknowledge.com.mutex.gmu.edu/full_record.do?product=MEDLINE&search_mode=AdvancedSearch&qid=3&SID=2CCAKeGnJ4AWExADGqh&page=1&doc=1" numdocs<-733 setwd("C:\\Users\\R3\\Downloads\\wos") # loading library library(stringr) # dowloading the html code and parsing data wosurl_str<-substr(wosurl, 1, (nchar(wosurl)-1)) for(k in 1:numdocs) { print(paste("--Record number: ",k," (out ",numdocs,")--",sep='')) url<-paste(wosurl_str,k,sep='') all_lines<-readLines(url) line<-all_lines[str_detect(all_lines,"UT=WOS:")] line_str<-unlist(strsplit(str_extract(line,"UT=WOS:.+"),"&")) wosut<-sub('WOS:','',line_str[1]) line<-all_lines[str_detect(all_lines,"NCBI_DB&PMID")] line_str<-unlist(strsplit(str_extract(line,"PMID.+"),"&")) pmid<-line_str[1] data<-cbind(pmid,wosut) write.table(data,file='wosut.txt',row.names=F,col.names=F,append=T,sep=",") write.table(all_lines,file=paste('wos',pmid,'.txt',sep=''),row.names=F,col.names=F,append=F) } # creating the search string for WoS uts<-read.csv(file="wosut.txt",header=F,sep=",",fill=T) uts<-subset(uts,uts[,2]!="") searchwos<-paste(uts[,2],collapse=' OR ') write.table(searchwos,file='search.txt',row.names=F,col.names=F,append=F,quote=F) 錯誤訊息: > # creating the search string for WoS > uts<-read.csv(file="wosut.txt",header=F,sep=",",fill=T) Error in read.table(file = file, header = header, sep = sep, quote = quote, : no lines available in input > uts<-subset(uts,uts[,2]!="") Error in subset(uts, uts[, 2] != "") : object 'uts' not found > searchwos<-paste(uts[,2],collapse=' OR ') Error in paste(uts[, 2], collapse = " OR ") : object 'uts' not found > write.table(searchwos,file='search.txt',row.names=F,col.names=F,append=F,quote=F) Error in is.data.frame(x) : object 'searchwos' not found > -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 69.143.188.208 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1440810668.A.527.html

08/29 10:31, , 1F
read.csv 是用來讀.csv檔 但你的file是.txt
08/29 10:31, 1F

08/29 10:32, , 2F
是著用read.table 不行的話讓大家下載你的資料
08/29 10:32, 2F

08/29 10:32, , 3F
很多高手就可以知道問題在哪了
08/29 10:32, 3F

08/29 10:39, , 4F
樓上不是這個問題喔XD 他write.table sep用comma,r
08/29 10:39, 4F

08/29 10:39, , 5F
ead.csv應該可以work
08/29 10:39, 5F

08/29 10:40, , 6F
他應該是寫入的data沒有資料才造成錯誤,不過要跑跑
08/29 10:40, 6F

08/29 10:40, , 7F
看程式才知道為啥沒寫入
08/29 10:40, 7F

08/29 10:45, , 8F
謝謝C大
08/29 10:45, 8F

08/29 10:55, , 9F
忘了說,我是校外用帳號密碼連那資料庫,請問要怎麼加這
08/29 10:55, 9F

08/29 10:55, , 10F
進去?
08/29 10:55, 10F
文章代碼(AID): #1LuGQiKd (R_Language)
文章代碼(AID): #1LuGQiKd (R_Language)