Skip to contents

This function gets tab-delimited data from an httr2_response and either saves it to a file or parses it into a data.frame in memory.

Usage

resp_body_tsv(resp, page = NULL, con = NULL, encoding = NULL)

Arguments

resp

httr2_response object, generated by e.g. httr2::req_perform() or fetch_stream()/fetch_paged().

page

integer (optional), response page number. If page > 1 then the table header is removed before saving to file. Only used when con is specified.

con

string or base::connection object (optional), the file in which to save the data.

encoding

string (optional), character encoding of the body text. If not specified, will use the encoding specified by the content-type, falling back to "UTF8" with a warning if it cannot be found. The resulting string is always re-encoded to UTF-8.

Value

By default, returns a data.frame. If con is not NULL, returns nothing and saves tab-delimited text to the file specified by con.

Examples

resp <- structure(
  list(method = "GET", url = "https://example.com",
       body = charToRaw("Entry\tGene Names (primary)\nP99999\tCYCS\n")),
  class = "httr2_response"
)

resp_body_tsv(resp)
#>    Entry Gene.Names..primary.
#> 1 P99999                 CYCS