Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Add an update.dataset() function #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions R/datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,43 @@ delete.datasets <- function(ws, name, host){
refresh(ws, "datasets")
ans
}

#' Update an existing R data frame in an AzureML workspace.
#'
#' Update an existing R data frame to an AzureML workspace using the \code{GenericTSV} format.
#'
#' @inheritParams refresh
#' @param x An R data frame object
#' @param name A character name for an existing AzureML dataset
#' @param description An optional character description of the dataset, description for the existing dataset will be used if none provided here
#' @param family_id An optional AzureML family identifier, family identifier for the existing dataset will be used if none provided here
#' @param ... Optional additional options passed to \code{write.table}
#' @note The additional \code{\link[utils]{write.table}} options may not include \code{sep} or \code{row.names} or \code{file}, but any other options are accepted.
#'
#' @return A single-row data frame of "Datasets" class that corresponds to the updated object now available in ws$datasets.
#' @importFrom curl curl_escape new_handle handle_setheaders handle_reset handle_setopt curl_fetch_memory
#' @importFrom jsonlite fromJSON
#' @export
#' @family dataset functions
#' @example inst/examples/example_update.R

update.dataset <- function(x, ws, name, description = "", family_id = "", ...)
{

# take care of exceptions from delete: it's Microsoft dataset or dataset does not exist
if (name %in% datasets(ws, filter = "samples")$Name) stop("Update not allowed for Microsoft sample datasets.")
else if (!(name %in% datasets(ws, filter = "my datasets")$Name)) stop("The dataset named '", name, "' does not exist.")

# check to make sure the existing file is in GenericTSV format
if (tolower(ws$datasets$DataTypeId[ws$datasets$Name == name]) != "generictsv") stop("The existing dataset is not of type GenericTSV.")

# use description and family_id from the existing dataset if no new values are provided
if (description == "") description = ws$datasets$Description[ws$datasets$Name == name]
if (family_id == "") family_id = ws$datasets$FamilyId[ws$datasets$Name == name]

# delete existing data
dr <- delete.datasets(ws, name)

# upload
upload.dataset(x, ws, name, description, family_id)
}
17 changes: 17 additions & 0 deletions inst/examples/example_update.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\dontrun{
library(AzureML)

ws <- workspace()

# Upload the R airquality data.frame to the workspace.
upload.dataset(airquality, ws, "airquality")

# Make an update by using only the first 10 rows
update.dataset(airquality[1:10, ], ws, "airquality")

# Download the updated dataset to check its content
download.datasets(ws, name = "airquality")

# Now delete what we've just uploaded
delete.datasets(ws, "airquality")
}