服务热线
178 0020 3020
任务一:
> library(DBI)
> library(RMySQL)
> con <- dbConnect(MySQL(),dbname="trymore",username="root",password="...")
> t_demo<-data.frame(a=seq(1:10), b=letters[1:10], c=rnorm(10))
> dbWriteTable(con, "t_demo", t_demo)
[1] TRUE
> dbListTables(con)
[1] "article" "t_demo" "word"
任务二:
> con <- dbConnect(MySQL(),dbname="trymore",username="root",password="...")
> library(RISmed)
> cell2017<-EUtilsSummary("cell[TA] AND 2017[DP]")
> data<-QueryId(cell2017)
> summary(cell2017)
Result count: 562
> pmid<- as.numeric(data)
> mylist<- list(id=1:562,pmid=pmid)
> mylist=as.data.frame(mylist)
> dbWriteTable(con,"article",mylist,append=T,row.names=F)
任务三:
> library(RMySQL)
> library(xml2)
> library(httr)
> library(stringr)
> con <- dbConnect(MySQL(),dbname="rdbb",username="root",password="199221")
> dbSendQuery(con,'SET NAMES utf8')
<MySQLResult:1364425037,580,0>
> rs <- dbSendQuery(con, "SELECT * FROM article WHERE isdone=0")
> while (!dbHasCompleted(rs)){
+ chunk<-dbFetch(rs,10)
+ pmid<- chunk[,3]
+ pmidstr<-paste(pmid,sep = "",collapse = ",")
+ postFetchUrl='https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi'
+ r2 <- POST(postFetchUrl,body=list(db='pubmed',id=pmidstr,retmode='xml'))
+ stop_for_status(r2)
+ data2=content(r2, "parsed", "application/xml")
+ article=xml_children(data2)
+ count=length(article)
+ cnt=1
+ while(cnt<=count){
+ title=xml_text(xml_find_first(article[cnt],".//ArticleTitle"))
+ abstract=xml_text(xml_find_first(article[cnt],".//AbstractText"))
+ pmid=xml_text(xml_find_first(article[cnt],".//PMID"))
+ title=str_replace_all(title,"\'", "")
+ abstract=str_replace_all(abstract,"\'", "")
+ sql=paste("UPDATE article SET title='",title,"',abstract='",abstract,"',isdone='1'"," where pmid='",pmid,"'",sep="")
+ con2 <- dbConnect(MySQL(),host="localhost",dbname="rdbb",user="root",password="199221")
+ dbSendQuery(con2,'SET NAMES utf8')
+ dbSendQuery(con2,sql)
+ dbDisconnect(con2)
+ cnt = cnt + 1
+ Sys.sleep(1)
+ }
+ }
结果:
报错:
附件