Opening a pickle file in R studio

Hello all,

How do I open a pkl file in r studio?

processed_results.pkl is the file.

I have tried:

require("reticulate")
source_python("Script.py")
pickle_data <-
read_pickle_file("/Users/emreyavuz/Downloads/vr_recordings_Emre/processed_results.pkl")

But this is not working!

Hi there,
What fun playing with R and Python!
Check out this link:
https://stackoverflow.com/questions/58472090/loading-pickle-in-r
First save the following Python code into a file called "read_pickle.py" in the current directory:

import pandas as pd
def read_pickle_file(file):
    pickle_data = pd.read_pickle(file)
    return pickle_data

Check your pickle file is in the same directory.
Then run this R code to read your pickle file and return it in an R object:

# install.packages('reticulate')
library("reticulate")
py_install("pandas")
# On Windows 10 I was asked to install conda (package manager), which I did.

py_install("pickle") # Not sure this line is needed - pickle may be built-in

source_python("read_pickle.py")
pickle_data <- read_pickle_file("your_file.pickle")

pickle_data

HTH

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.