R科研作图学习小组

http://group.keyangou.com/RGraph
组长: 管理员:
  • 访问次数:15620
  • 小组等级:8
  • 话题:567
  • 回答:34
  • 签到:357
  • 小组排名:
  • R2-14 2阶段2

    lucyylx 发布于:2018.01.26

    任务一:

    > 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)

    图片_1.jpg




    任务三:

    > 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)

    +     }

    + }


    结果:

    1.jpg

    报错:

    2.jpg




     

     

     

     
    0条评论 123浏览 邀请回答
    沙发空缺中~

    小组告示

    科研狗 2012-2016 京ICP备16006621 科研好助手,专业的科研社交共享平台