Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added snippet to read RDS files in an R notebook #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions articles/machine-learning/how-to-r-interactive-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ You can also use a Datastore URI to access different files on a registered Datas
})
print(df)
```

Using the same filestore object, you can read an RDS file, but you need to decompress the bytes before passing it to `readRDS()` as a `rawConnection`

3. Read a serialized R object file (.RDS):
```r
funcs <- import_builtins() # Add this with the other imports, gives access to built-in Python functions such as `list()`


r_object <- with(fs$open("<path>)", "r") %as% f, {
x <- as.raw(funcs$list(f$read))
decompressed_x <- memDecompress(x, type = "gzip", asChar = "FALSE")
conn <- rawConnection(decompressed_raw)
readRDS(conn) # readRDS will decompress automatically if provided with a path, but won't decompress if provided with a rawConnection
})
print(r_object)
```

## Install R packages

Expand Down