在R中下载xml文件以及如何在S5类中编写R包?

时间:2015-03-22 04:05:49

标签: xml r package s4

两个问题使我感到困惑:

  1. 如何在R控制台中下载'xml'文件?

  2. 我想通过'S4 class'制作一个R pcakage,但很多功能我

  3. 仍然不知道,比如如何设置变量环境'new.env'et

    al;我掌握的是一些基本功能;因此,可以提出任何关于

    的建议

    如何在'S4'类中编写R函数,并将它们集成到一个包中?

    问题1如下:

    我想在

    中下载'xml'文件

    http://www.broadinstitute.org/gsea/downloads.jsp

    and the filename is 'msigdb_v5.0.xml' .
    

    我不想在我的计算机中下载该文件,然后通过'XML'包解析它;

    我尝试过如下:

    Method 1:  
    
        download.file('http://www.broadinstitute.org/gsea/downloads.jsp','msigdb_v5.0.xml')
    
    It showed :
    
        trying URL 'http://www.broadinstitute.org/gsea/downloads.jsp'
    
        Content type 'text/html' length 5070 bytes
    
        opened URL
    
        downloaded 5070 bytes
    
    Method 2: 
    
        library(XML)
    
        path="http://www.broadinstitute.org/gsea/msigdb/download_file.jsp?
    
        filePath=/resources/msigdb/5.0/msigdb_v5.0.xml"
    
        file=xmlParse(path)
    
    It showed error:
    
        Input is not proper UTF-8, indicate encoding !
    
        Bytes: 0xA9 0x20 0x32 0x30
    
        Opening and ending tag mismatch: div line 68 and a
    
        Entity 'nbsp' not defined
    
        Entity 'nbsp' not defined
    
        Entity 'nbsp' not defined
    
        Entity 'nbsp' not defined
    
        Opening and ending tag mismatch: body line 34 and div
    
        Opening and ending tag mismatch: html line 25 and body
    
        Extra content at the end of the document
    
        Error: 1: Input is not proper UTF-8, indicate encoding !
    
                   Bytes: 0xA9 0x20 0x32 0x30
    
               2: Opening and ending tag mismatch: div line 68 and a
    
               3: Entity 'nbsp' not defined
    
               4: Entity 'nbsp' not defined
    
               5: Entity 'nbsp' not defined
    
               6: Entity 'nbsp' not defined
    
               7: Opening and ending tag mismatch: body line 34 and div
    
               8: Opening and ending tag mismatch: html line 25 and body
    
               9: Extra content at the end of the document
    
    Method 3.
    
         library(RCurl)
    
         path='http://www.broadinstitute.org/gsea/msigdb/download_file.jsp?
    
         filePath=/resources/msigdb/5.0/msigdb_v5.0.xml'
    
         readHTMLTable(path,encoding="UTF-8")
    
      also,method 3 was error again!
    

0 个答案:

没有答案