has_bom: Tests whether a raw httr response or character vector has a...

View source: R/bom.r

has_bomR Documentation

Tests whether a raw httr response or character vector has a byte order mark (BOM)

Description

What is a byte order mark?

Usage

has_bom(resp, encoding = "UTF-8")

Arguments

resp

httr response object or a character vector

encoding

can be one of UTF-8, UTF-16 or UTF-16BE. Although a BOM could be used with UTF-32 and other encodings, such encodings are rarely used for data transmission and the three supported encodings are the most likely ones folks in R will be working with from web APIs.

This function defaults to looking for UTF-8 BOM, but you can override it.

Value

TRUE if response contains a BOM, NA if an unsupported encoding was passed (along with a message)

Author(s)

@hrbrmstr

References

UTF-8, UTF-16, UTF-32 & BOM

Examples

library(httr)
foo <- GET("http://www.claritin.com/webservice/allergyforecast.php?zip=33956")
has_bom(foo)

cfoo <- content(foo, as="text")
has_bom(cfoo)

has_bom(GET("http://google.com"))

hrbrmstr/hrbrmisc documentation built on May 1, 2023, 7:39 a.m.