# File$open

### File$<mark style="color:purple;">**open**</mark>**(*****mode="r"*****)** → [connection](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/connections)

Open a connection to the file. Note that by default the underlying stream won't be closed until fully consumed – it is strongly recommended to add `on.exit(connection.close())` after opening the file.

You may also use the R-native `open(file)` to open a connection to the file.

### **Parameters:**

**`mode` :&#x20;*****"r" | "rb" | "rt", default "r"***\
Whether to read the file as text or binary. Similar to default R file behavior, defaults to text mode ("r"). "rb" is for binary mode. "rt" is an alias for "r".

### **Returns:**

[**connection**](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/connections)

### Examples

```r
# See https://redivis.com/datasets/yz1s-d09009dbb/files for example data
t <- redivis$table("demo.example_data_files:yz1s:v1_3.example_file_types:4c10")

text_file <- t$file("pandas_core.py")
con <- text_file$open()
readLines(con)

binary_file <- t$file("bogota.tiff")
con <- binary_file$open("rb")
readBin(con)
```
