看板 R_Language 關於我們 聯絡資訊
我嘗試抓 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
allen1985: read.csv 是用來讀.csv檔 但你的file是.txt 08/29 10:31
allen1985: 是著用read.table 不行的話讓大家下載你的資料 08/29 10:32
allen1985: 很多高手就可以知道問題在哪了 08/29 10:32
celestialgod: 樓上不是這個問題喔XD 他write.table sep用comma,r 08/29 10:39
celestialgod: ead.csv應該可以work 08/29 10:39
celestialgod: 他應該是寫入的data沒有資料才造成錯誤,不過要跑跑 08/29 10:40
celestialgod: 看程式才知道為啥沒寫入 08/29 10:40
allen1985: 謝謝C大 08/29 10:45
evilove: 忘了說,我是校外用帳號密碼連那資料庫,請問要怎麼加這 08/29 10:55
evilove: 進去? 08/29 10:55