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

Commit 3e4a89d

Browse files
author
Timothée Poisot
committed
Re. issue #12 -- function releaseDataset to make a dataset public
Includes a version bump to 0.3.0 to reflect new function
1 parent 9bddef2 commit 3e4a89d

9 files changed

+87
-4
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: rmangal
2-
Version: 0.2.1
2+
Version: 0.3.0
33
Date: 2014-01-14
44
Title: R interface to the mangal database of ecological networks
55
Author: Tim Poisot <t.poisot@gmail.com>

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export(patchPopulation)
3838
export(patchReference)
3939
export(patchTaxa)
4040
export(patchTrait)
41+
export(releaseDataset)
4142
export(toCheddar)
4243
export(toIgraph)
4344
export(whatIs)

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
rmangal 0.3.0
2+
=============
3+
* Added functions to release a dataset (and all objects attached to it)
4+
15
rmangal 0.2.1
26
=============
37
* Bug fix due to changes in how json objects are rendered by the parser

R/dataset_methods.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ patchDataset <- function(api, data)
5151
if(!is.null(data$data)) data$data <- multi_resToURI(api, data$data, 'reference')
5252
if(!is.null(data$environment)) data$environment <- multi_resToURI(api, data$environment, 'environment')
5353
mangalPatch(api, 'dataset', data)
54-
}
54+
}

R/mangalPatch.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Patch an object
1+
#' @title Patch an object
22
#'
33
#' Patch an existing object
44
#'

R/release_dataset.R

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#' @title Release a resource
2+
#' @description
3+
#' This function is used internally to release a resource. It do not returns
4+
#' anything, but throws a warning if there is no public field to update.
5+
releaseResource <- function(api, type, id)
6+
{
7+
resource <- mangalGet(api, type, id)
8+
if(is.null(resource$public))
9+
{
10+
warning(str_c("The resource ", type, '/', id, " has no public field"))
11+
} else {
12+
resource$public <- TRUE
13+
mangalPatch(api, type, resource)
14+
}
15+
}
16+
17+
#' @title Release a dataset
18+
#' @description
19+
#' Releases a dataset, and all objects of lower level (networks and
20+
#' interactions).
21+
#'
22+
#' @param api a \code{\link{mangalapi}} object
23+
#' @param id the id of the dataset to release
24+
#' @param force whether to force release even if the dataset is already public
25+
#'
26+
#' @export
27+
releaseDataset <- function(api, id, force=FALSE)
28+
{
29+
dataset <- getDataset(api, id)
30+
if(dataset$public & (! force)) stop("This dataset is already public")
31+
# We go through 1) the list of networks, 2) the list of interactions
32+
for(net_id in dataset$networks)
33+
{
34+
net <- getNetwork(api, net_id)
35+
releaseResource(api, 'network', net_id)
36+
for(int_id in net$interactions)
37+
{
38+
releaseResource(api, 'interaction', int_id)
39+
}
40+
}
41+
releaseResource(api, 'dataset', id)
42+
}
43+

man/mangalPatch.Rd

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
\name{mangalPatch}
22
\alias{mangalPatch}
3-
\title{Patch an object}
3+
\title{Patch an object
4+
5+
Patch an existing object}
46
\usage{
57
mangalPatch(api, type, data)
68
}
@@ -12,6 +14,8 @@ mangalPatch(api, type, data)
1214
\item{data}{the object in list form}
1315
}
1416
\description{
17+
Patch an object
18+
1519
Patch an existing object
1620
}
1721

man/releaseDataset.Rd

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
\name{releaseDataset}
2+
\alias{releaseDataset}
3+
\title{Release a dataset}
4+
\usage{
5+
releaseDataset(api, id, force = FALSE)
6+
}
7+
\arguments{
8+
\item{api}{a \code{\link{mangalapi}} object}
9+
10+
\item{id}{the id of the dataset to release}
11+
12+
\item{force}{whether to force release even if the dataset
13+
is already public}
14+
}
15+
\description{
16+
Releases a dataset, and all objects of lower level
17+
(networks and interactions).
18+
}
19+

man/releaseResource.Rd

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\name{releaseResource}
2+
\alias{releaseResource}
3+
\title{Release a resource}
4+
\usage{
5+
releaseResource(api, type, id)
6+
}
7+
\description{
8+
This function is used internally to release a resource. It
9+
do not returns anything, but throws a warning if there is
10+
no public field to update.
11+
}
12+

0 commit comments

Comments
 (0)