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

Commit 9aa4de1

Browse files
committed
Merge branch 'dev'
2 parents 66fdc2a + 66f8594 commit 9aa4de1

33 files changed

+2012
-711
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Package: AzureML
22
Type: Package
3-
Title: Interface with Azure Machine Learning datasets and web services
3+
Title: Interface with Azure Machine Learning Datasets, Experiments and Web Services
44
Description: Functions and datasets to support Azure Machine Learning. This
55
allows you to interact with datasets, as well as publish and consume R functions
66
as API services.
7-
Version: 0.2.9
8-
Date: 2016-01-28
7+
Version: 0.2.10
8+
Date: 2016-01-30
99
Authors@R: c(
10-
person("Raymond", "Laghaeian", role=c("aut", "cre"), email="raymondl@microsoft.com"),
10+
person("Andrie", "de Vries", role=c("aut", "cre"), email="adevries@microsoft.com"),
1111
person(family="Microsoft Corporation", role="cph"),
1212
person(family="Revolution Analytics", role="cph", comment="Code adapted from the foreach package")
1313
)
@@ -30,6 +30,7 @@ Imports:
3030
Suggests:
3131
testthat,
3232
knitr,
33+
rmarkdown,
3334
lme4,
3435
gbm,
3536
MASS

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ importFrom(jsonlite,fromJSON)
4242
importFrom(jsonlite,toJSON)
4343
importFrom(miniCRAN,makeRepo)
4444
importFrom(miniCRAN,pkgDep)
45+
importFrom(stats,runif)
46+
importFrom(stats,setNames)
47+
importFrom(utils,capture.output)
48+
importFrom(utils,head)
49+
importFrom(utils,read.table)
50+
importFrom(utils,str)
51+
importFrom(utils,write.table)
52+
importFrom(utils,zip)
4553
importFrom(uuid,UUIDgenerate)

R/azureml-package.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@
7373
#' @aliases AzureML
7474
#' @docType package
7575
#' @keywords package
76+
#'
77+
#' @importFrom stats runif setNames
78+
#' @importFrom utils capture.output head read.table str write.table zip
7679
NULL
80+

R/datasets.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,20 @@ delete.datasets <- function(ws, name, host){
214214
h <- new_handle()
215215
handle_setheaders(h, .list = ws$.headers)
216216
handle_setopt(h, customrequest = "DELETE")
217-
status_code <- vapply(datasets$FamilyId,
218-
function(familyId){
219-
uri <- sprintf("%s/workspaces/%s/datasources/family/%s",
220-
ws$.studioapi,
221-
curl_escape(ws$id),
222-
curl_escape(familyId)
223-
)
224-
try_fetch(uri, h)$status_code
225-
}, 1, USE.NAMES = FALSE
226-
)
217+
delete_one <- function(familyId){
218+
uri <- sprintf("%s/workspaces/%s/datasources/family/%s",
219+
ws$.studioapi,
220+
curl_escape(ws$id),
221+
curl_escape(familyId)
222+
)
223+
z <- try_fetch(uri, h, tries = 3, delay = 2)
224+
z$status_code
225+
}
226+
status_code <- vapply(datasets$FamilyId, delete_one, FUN.VALUE = numeric(1), USE.NAMES = FALSE)
227227
ans = data.frame(
228-
Name = datasets$Name,
229-
Deleted=status_code < 300,
230-
status_code=status_code,
228+
Name = datasets$Name,
229+
Deleted = status_code < 300,
230+
status_code = status_code,
231231
stringsAsFactors = FALSE
232232
)
233233
refresh(ws, "datasets")

R/fetch.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ validate_response <- function(r){
6161
}
6262
}
6363

64-
#' Try to fetch a uri/handle, retrying on certain returned status codes after a timeout.
65-
#'
66-
#' @param uri the uri to fetch
67-
#' @param handle a curl handle
68-
#' @param retry_on HTTP status codes that result in retry
69-
#' @param tries number of tries before failing
70-
#' @param delay in seconds between retries, subject to exponent
71-
#' @param exponent increment each successive delay by delay^exponent
72-
#' @param no_message_threshold Only show messages if delay is greater than this limit
73-
#'
74-
#' @keywords Internal
75-
#' @return the result of curl_fetch_memory(uri, handle)
76-
#'
64+
# Try to fetch a uri/handle, retrying on certain returned status codes after a timeout.
65+
#
66+
# @param uri the uri to fetch
67+
# @param handle a curl handle
68+
# @param retry_on HTTP status codes that result in retry
69+
# @param tries number of tries before failing
70+
# @param delay in seconds between retries, subject to exponent
71+
# @param exponent increment each successive delay by delay^exponent
72+
# @param no_message_threshold Only show messages if delay is greater than this limit
73+
#
74+
# @keywords Internal
75+
# @return the result of curl_fetch_memory(uri, handle)
76+
#
7777
try_fetch <- function(uri, handle,
7878
retry_on = c(400, 401, 440, 503, 504, 509),
7979
tries = 6,
8080
delay = 1, exponent = 2,
8181
no_message_threshold = 1)
8282
{
8383
collisions = 1
84-
while(collisions < tries) {
84+
while(collisions < (tries + 1)) {
8585
r = curl_fetch_memory(uri, handle)
8686
if(!(r$status_code %in% retry_on)) {
8787
validate_response(r)

R/internal.R

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ urlconcat <- function(a,b)
2828
ans
2929
}
3030

31-
#' Internal function that retrieves datasets.
32-
#'
33-
#' @param ws A workspace object
34-
#' @return a data.frame
31+
# Internal function that retrieves datasets.
32+
#
33+
# @param ws A workspace object
34+
# @return a data.frame
3535
#' @importFrom curl handle_setheaders curl new_handle
3636
#' @importFrom jsonlite fromJSON
37-
#' @keywords Internal
37+
# @keywords Internal
3838
get_datasets <- function(ws) {
3939
h = new_handle()
4040
handle_setheaders(h, .list = ws$.headers)
@@ -78,13 +78,13 @@ convertToDate <- function(x) {
7878
}
7979

8080

81-
#' Internal function that retrieves experiments.
82-
#'
83-
#' @param ws A workspace object
84-
#' @return a data.frame
81+
# Internal function that retrieves experiments.
82+
#
83+
# @param ws A workspace object
84+
# @return a data.frame
8585
#' @importFrom curl handle_setheaders curl new_handle
8686
#' @importFrom jsonlite fromJSON
87-
#' @keywords Internal
87+
# @keywords Internal
8888
get_experiments <- function(ws) {
8989
h = new_handle()
9090
handle_setheaders(h, .list=ws$.headers)
@@ -108,16 +108,16 @@ get_experiments <- function(ws) {
108108
x
109109
}
110110

111-
#' Internal function that retrieves a dataset from AzureML.
112-
#'
113-
#' @param x a list or data.frame with \code{DownloadLocation} and \code{DataTypeId} fields
114-
#' @param h optional curl handle
115-
#' @param quote passed to \code{\link[utils]{read.table}}
116-
#' @param ... additional parameters to pass to \code{read.table}
117-
#' @return a data.frame
111+
# Internal function that retrieves a dataset from AzureML.
112+
#
113+
# @param x a list or data.frame with \code{DownloadLocation} and \code{DataTypeId} fields
114+
# @param h optional curl handle
115+
# @param quote passed to \code{\link[utils]{read.table}}
116+
# @param ... additional parameters to pass to \code{read.table}
117+
# @return a data.frame
118118
#' @importFrom foreign read.arff
119119
#' @importFrom curl new_handle curl
120-
#' @keywords Internal
120+
# @keywords Internal
121121
get_dataset <- function(x, h, quote = "\"", ...) {
122122
# Set default stringsAsFactors to FALSE, but allow users to override in ...
123123
# Restore the option on function exit.
@@ -153,16 +153,17 @@ zipAvailable <- function(){
153153

154154
zipNotAvailableMessage = "Requires external zip utility. Please install zip, ensure it's on your path and try again."
155155

156-
#' Package a Function and Dependencies into an Environment
157-
#'
158-
#' @param exportenv R environment to package
159-
#' @param packages a character vector of required R package dependencies
160-
#' @param version optional R version
161-
#' @return A base64-encoded zip file containing the saved 'exportenv' environment
156+
157+
# Package a Function and Dependencies into an Environment
158+
#
159+
# @param exportenv R environment to package
160+
# @param packages a character vector of required R package dependencies
161+
# @param version optional R version
162+
# @return A base64-encoded zip file containing the saved 'exportenv' environment
162163
#' @import codetools
163164
#' @importFrom base64enc base64encode
164165
#' @importFrom miniCRAN makeRepo pkgDep
165-
#' @keywords Internal
166+
# @keywords Internal
166167
packageEnv <- function(exportenv, packages=NULL, version="3.1.0") {
167168
if(!zipAvailable()) stop(zipNotAvailableMessage)
168169
if(!is.null(packages)) assign("..packages", packages, envir=exportenv)

R/methods.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ print.Datasets <- function(x, ...)
110110
str.Workspace <- function(object, ...){
111111
NextMethod(object)
112112
cat("list with elements:\n")
113-
cat(ls(ws, all.names = TRUE))
113+
cat(ls(object, all.names = TRUE))
114114
cat("\n\n")
115115
cat("Values:\n")
116116
cat("$ id :", object$id, "\n")

R/publish.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
wrapper = "inputDF <- maml.mapInputPort(1)\nload('src/env.RData')\n if(!is.null(exportenv$..packages))\n {\n install.packages(exportenv$..packages, repos=paste('file:///',getwd(),'/src/packages',sep=''), lib=getwd());.libPaths(new=getwd())\n lapply(exportenv$..packages, require, quietly=TRUE, character.only=TRUE)}\nparent.env(exportenv) = globalenv()\n\nattach(exportenv, warn.conflicts=FALSE)\nif(..data.frame){outputDF <- data.frame(..fun(inputDF)); colnames(outputDF) <- ..output_names} else{outputDF <- matrix(nrow=nrow(inputDF), ncol=length(..output_names)); colnames(outputDF) <- ..output_names; outputDF <- data.frame(outputDF); for(j in 1:nrow(inputDF)){outputDF[j, ] <- do.call('..fun', as.list(inputDF[j,]))}}\nmaml.mapOutputPort(\"outputDF\")"
2929

30-
#' Test the AzureML wrapper locally
31-
#' @param inputDF data frame
32-
#' @param wrapper the AzureML R wrapper code
33-
#' @param fun a function to test
34-
#' @param output_names character vector of function output names
35-
#' @param data.frame i/o format
30+
# Test the AzureML wrapper locally
31+
# @param inputDF data frame
32+
# @param wrapper the AzureML R wrapper code
33+
# @param fun a function to test
34+
# @param output_names character vector of function output names
35+
# @param data.frame i/o format
3636
test_wrapper <- function(inputDF, wrapper, fun, output_names, `data.frame`)
3737
{
3838
exportenv = new.env()

R/workspace.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ default_api <- function(api_endpoint = "https://studioapi.azureml.net"){
6464
#' Workspace ID
6565
#'
6666
#' \if{html}{\figure{workspace_id.png}{options: width="60\%" alt="Figure: workspace_id.png"}}
67+
#' \if{latex}{\figure{workspaceId.pdf}{options: width=7cm}}
6768
#'
6869
#'
6970
#'
7071
#' Authorization token
7172
#'
7273
#' \if{html}{\figure{authorization_token.png}{options: width="60\%" alt="Figure: authorization_token.png"}}
73-
#'
74-
#'
75-
# \if{latex}{\figure{mai.pdf}{options: width=7cm}}
74+
#' \if{latex}{\figure{authorizationToken.pdf}{options: width=7cm}}
7675
#'
7776
#' @section Using a \code{settings.json} file:
7877
#' If any of the \code{id}, \code{auth}, \code{api_endpoint} or \code{management_endpoint} arguments are missing, the function attempts to read values from the \code{config} file with JSON format:
@@ -89,8 +88,8 @@ default_api <- function(api_endpoint = "https://studioapi.azureml.net"){
8988
#'
9089
#' @param id Optional workspace id from ML studio -> settings -> WORKSPACE ID. See the section "Finding your AzureML credentials" for more details.
9190
#' @param auth Optional authorization token from ML studio -> settings -> AUTHORIZATION TOKENS. See the section "Finding your AzureML credentials" for more details.
92-
#' @param api_endpoint Optional AzureML API web service URI. Defaults to \url{https://studioap.azureml.net} if not provided and not specified in config. See note.
93-
#' @param management_endpoint Optional AzureML management web service URI. Defaults to \url{https://management.azureml.net} if not provided and not specified in config. See note.
91+
#' @param api_endpoint Optional AzureML API web service URI. Defaults to \code{https://studioap.azureml.net} if not provided and not specified in config. See note.
92+
#' @param management_endpoint Optional AzureML management web service URI. Defaults to \code{https://management.azureml.net} if not provided and not specified in config. See note.
9493
#' @param config Optional settings file containing id and authorization info. Used if any of the other arguments are missing. The default config file is \code{~/.azureml/settings.json}, but you can change this location by setting \code{options(AzureML.config = "newlocation")}. See the section "Using a settings.json file" for more details.
9594
#' @param ... ignored
9695
#' @param .validate If TRUE, makes a request to the AzureML API to retrieve some data. This validates whether the workspace id and authorization token are valid. Specifically, the function calls \code{\link{datasets}}. This should normally be set to TRUE. Set this to FALSE for testing, or if you know that your credentials are correct and you don't want to retrieve the datasets.

0 commit comments

Comments
 (0)