Save array into Managed Folder from R Notebook

Options
nadine
nadine Registered Posts: 1
edited July 16 in Using Dataiku

Hi

I want to save a data object from an R notebook in a managed folder on DSS so it can be read by a Jupyter notebook.

I am using

# data must be a connection providing the data to upload
data = c(0,1.1,2.2,3.3)
dkuManagedFolderUploadPath("folder_name", "path_in_folder", data)

To upload the data but I am getting the following error:

Error in readBin(arr, double(), 6, size = 4): can only read from a binary connection
Traceback:

1. readBin(arr, double(), 6, size = 4)

How can I solve this readBin error?


Operating system used: Windows

Answers

  • Zach
    Zach Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 153 Dataiker
    edited July 17
    Options

    Hi @nadine
    ,

    dkuManagedFolderUploadPath expects a connection object, not a vector. You'll need to save your data object to a temporary file first:

    # Save `data` to a managed folder
    library(dataiku)
    
    data = c(0,1.1,2.2,3.3)
    temp_filename <- tempfile("r-managed-folder-")
    save(data, file=temp_filename)
    temp_connection <- file(temp_filename, "rb")
    dkuManagedFolderUploadPath("folder_name", "path_in_folder", temp_connection)

    You can then load the data object using the following code:

    # Load `data` from a managed folder
    library(dataiku)
    
    raw_data <- dkuManagedFolderDownloadPath("folder_name", "path_in_folder", as="raw")
    temp_filename <- tempfile(pattern="r-managed-folder-")
    writeBin(raw_data, temp_filename)
    load(temp_filename)
    cat(data, sep="\n")

    Thanks,

    Zach

Setup Info
    Tags
      Help me…