zipArchive           package:Rcompression           R Documentation

_C_o_n_s_t_r_u_c_t_o_r _f_o_r _o_b_j_e_c_t _r_e_p_r_e_s_e_n_t_i_n_g _Z_I_P _a_r_c_h_i_v_e _o_n _d_i_s_k

_D_e_s_c_r_i_p_t_i_o_n:

     This is a simple function that takes the name of a file and labels
     it with an S3 class so that programmers can then access
     information about and contents in  the ZIP archive.  The purpose
     of this is function is to return an object with the appropriate
     information so that the external ZIP file/archive can be treated
     as a list via '$', '[' and '[[' operations and one can add
     elements via '[[<-'.

     By default, this checks the file exists. If one wants to use this
     to identify a ZIP file that you will create, you will want to use
     'check = FALSE'.

     The 'class' parameter allows more specialized constructors to use
     this function to create objects with more detailed class
     information.  Using  'setOldClass' would probably be more
     appropriate.

_U_s_a_g_e:

     zipArchive(filename, check = TRUE, class = "ZipArchive")

_A_r_g_u_m_e_n_t_s:

filename: the name of the ZIP file. This is passed to 'path.expand'.

   check: a logical value indicating whether to raise an error if the
          file doesn't exist.

   class: a character vector giving the name(s) of the S3 classes for
          the resulting object.

_V_a_l_u_e:

     A character vector giving the expanded name of the specified file
     with the specified 'class' vector as the class attribute.

     For the element accessor operators ('$', '[' and '[['), the
     contents of the specified file(s) within the archive are returned.

     For the assignment operators ('$<-', '[<-' and '[[<-'), the
     updated archive object is returned.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang

_S_e_e _A_l_s_o:

     'getZipInfo'

_E_x_a_m_p_l_e_s:

       f = system.file("sampleData", "MyZip.zip", package = "Rcompression")
       ar = zipArchive(f)
       names(ar)
       length(ar)
       ar[["FAQ.html"]]
       ar[["bunzip"]]  # partial matching
       ar[".*"]  # regular expression

       f = system.file("sampleData", "tests.zip", package = "Rcompression")
       ar = zipArchive(f)
        
       names(ar)
       length(ar)

          # This needs a password to access the contents of any of the file.
          # The password is the string "password" (pretty simple).
       ar[["files.R", password = "password"]]

          # without the password, we'd have an error.
       try(ar[["files.R"]])

         # 
       f = system.file("sampleData", "Empty.docx", package = "Rcompression")
       tgt = paste(tempdir(), "word.docx", sep = .Platform$file.sep)
       file.copy(f, tgt)

       ar = zipArchive(tgt)

       tmp = tempfile()
       cat("This is some text\nin a file", file = tmp)
       ar[["fromFile"]] = tmp

       ar[["fromAsIs"]] = I("Text/that/shouldn't be mistaken for a file")
       ar[["fromText"]] = "more heuristic text"
       names(ar)

       ar["one"] = tmp

       ar[c("two", "fromAsIs")] = list(tmp, I("Text/that/shouldn't be mistaken for a file"))
       names(ar)


        #### 
         # In memory archives

       contents = loadZip(system.file("sampleData", "Empty.docx", package = "Rcompression"))
       ar = zipArchive(contents)
       names(ar)
       length(ar)

       if(require(RCurl)) {

          data = getURLContent('http://www.ecb.int/stats/eurofxref/eurofxref-hist.zip?1a1b5dbb25d31898b347736783bd440a')
          ar = zipArchive(data)
          read.csv(textConnection(ar[[1]]), header = TRUE, na.strings = "N/A")
       }
       

