Skip to content

Commit

Permalink
Merge pull request #195 from aghaynes/globalenv
Browse files Browse the repository at this point in the history
Globalenv fix for CRAN submission
  • Loading branch information
Patrick R. Wright authored Apr 16, 2020
2 parents 9329314 + 98eab4c commit 5be910e
Show file tree
Hide file tree
Showing 42 changed files with 260 additions and 189 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: secuTrialR
Type: Package
Title: Handling of Data from the Clinical Data Management System 'secuTrial'
Version: 1.0.2
Version: 1.0.3
Authors@R:
c(person(given = "Patrick R.",
family = "Wright",
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# secuTrialR 1.0.1, 1.0.2
# secuTrialR 1.0.1, 1.0.2, 1.0.3
* adjustments to handle review feedback from CRAN (#190)

# secuTrialR 1.0.0
Expand Down
36 changes: 23 additions & 13 deletions R/asdataframe.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#' as.data.frame method for secuTrialdata objects
#'
#' Make the data from the exports more easily accessible by placing them in
#' another environment (e.g. place them in the global environment
#' (\code{.GlobalEnv}) and you can reference them without referring to the
#' \code{secuTrialdata} object anymore. Ie. they become regular \code{data.frame}s).
#' @param x \code{secuTrialdata} object
#' @param ... further parameters
#' @param envir environment in which to put the data (e.g. \code{.GlobalEnv})
#' @param data.frames character vector of data.frame names to turn into data.frames
#' @param meta logical should metadata be returned
#' @param regex regex syntax to remove from names
#' @param rep replacement for regex
#' @param envir environment in which to put the data
#'
#' @return each data.frame on the \code{secuTrialdata} object is saved to it's own data.frame in the environment
#' @param ... further parameters
#' @details \code{envir} must be specifically defined. For simplicity,
#' \code{.GlobalEnv} would probably be the easiest (assigning it to another
#' environment would still entail referring to that environment).
#' @return each \code{data.frame} in the \code{secuTrialdata} object is saved to it's
#' own \code{data.frame} in the designated environment
#' @export
#'
#' @examples
Expand All @@ -18,16 +24,20 @@
#' package = "secuTrialR")
#' # load all export data
#' sT_export <- read_secuTrial_raw(data_dir = export_location)
#' # add files to global environment
#' as.data.frame(sT_export)
#' # add files to global environment, removing the project name from the file names
#' as.data.frame(sT_export, regex = "ctu05")
as.data.frame.secuTrialdata <- function(x, ...,
#' # add files to a new environment called env1
#' env1 <- new.env()
#' as.data.frame(sT_export, envir = env1)
#' # add files to a new environment called env2, removing the project name from
#' # the file names
#' env2 <- new.env()
#' as.data.frame(sT_export, regex = "ctu05", envir = env2)
as.data.frame.secuTrialdata <- function(x,
...,
envir,
data.frames = NULL,
meta = FALSE,
regex = NULL,
rep = "",
envir = .GlobalEnv
rep = ""
) {

if (all(!is.character(regex), !is.null(regex))) stop("regex should be either NULL or character")
Expand All @@ -49,7 +59,7 @@ as.data.frame.secuTrialdata <- function(x, ...,
function(orig_name, new_name) {
assign(new_name, x[[orig_name]], envir = envir)
},
datanames, datanames2)
datanames, datanames2)
)

}
19 changes: 15 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ dat <- d %>%
`secuTrialR` has a couple of functions to help get to grips with a secuTrial data export. They are intended to be used in an exploratory manner only.

#### as.data.frame
Working with a list can be tiresome so `secuTrialR` provides a `as.data.frame` method to save the `data.frames` in the list to an environment of your choice.
Working with a list can be tiresome so `secuTrialR` provides a `as.data.frame` method to save the `data.frames` in the list to an environment of your choice.
As a demonstration, we'll create a new environment (`env`) and create the `data.frame`s in there. In practice, using `.GlobalEnv` would probably be more useful.

```{r}
ls()
env <- new.env()
ls(env)
names(ctu05)
as.data.frame(ctu05)
ls()
as.data.frame(ctu05, envir = env)
ls(env)
```

There are also options for selecting specific forms (option `data.frames`), changing names based on regex (options `regex` and `rep`) and specifying whether metadata objects should be returned (option `meta`).
Expand Down Expand Up @@ -336,13 +338,22 @@ R CMD check secuTrialR_0.9.0.tar.gz
```

### Versioning and releases

The version number is made up of three digits. The first digit
is reserved for major releases which may break backwards compatibility.
The second and third digits are used for medium and minor changes respectively.
Versions released on CRAN will be tagged and saved as releases on GitHub.
The version released on CRAN is regarded as the stable version while
the master branch on GitHub is regarded as the current development version.

#### Release checklist

Compile/Update:
* README.Rmd
* vignette
* pkgdown page
* NEWS.md

### Guidelines for contributors

Requests for new features and bug fixes should first be documented as an [Issue](https://github.com/SwissClinicalTrialOrganisation/secuTrialR/issues) on GitHub.
Expand Down
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->


# secuTrialR [![](https://img.shields.io/badge/version-1.0.2-blue.svg)](https://github.com/SwissClinicalTrialOrganisation/secuTrialR) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/SwissClinicalTrialOrganisation/secuTrialR?branch=master&svg=true)](https://ci.appveyor.com/project/SwissClinicalTrialOrganisation/secuTrialR) [![travis](https://api.travis-ci.com/SwissClinicalTrialOrganisation/secuTrialR.svg?branch=master)](https://travis-ci.com/github/SwissClinicalTrialOrganisation/secuTrialR) [![codecov](https://codecov.io/github/SwissClinicalTrialOrganisation/secuTrialR/branch/master/graphs/badge.svg)](https://codecov.io/github/SwissClinicalTrialOrganisation/secuTrialR)
# secuTrialR [![](https://img.shields.io/badge/version-1.0.3-blue.svg)](https://github.com/SwissClinicalTrialOrganisation/secuTrialR) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/SwissClinicalTrialOrganisation/secuTrialR?branch=master&svg=true)](https://ci.appveyor.com/project/SwissClinicalTrialOrganisation/secuTrialR) [![travis](https://api.travis-ci.com/SwissClinicalTrialOrganisation/secuTrialR.svg?branch=master)](https://travis-ci.com/github/SwissClinicalTrialOrganisation/secuTrialR) [![codecov](https://codecov.io/github/SwissClinicalTrialOrganisation/secuTrialR/branch/master/graphs/badge.svg)](https://codecov.io/github/SwissClinicalTrialOrganisation/secuTrialR)

An R package to handle data from the clinical data management system (CDMS) [secuTrial](https://www.secutrial.com/en/).

Expand Down Expand Up @@ -284,16 +284,17 @@ dat <- d %>%
`secuTrialR` has a couple of functions to help get to grips with a secuTrial data export. They are intended to be used in an exploratory manner only.

#### as.data.frame
Working with a list can be tiresome so `secuTrialR` provides a `as.data.frame` method to save the `data.frames` in the list to an environment of your choice.
Working with a list can be tiresome so `secuTrialR` provides a `as.data.frame` method to save the `data.frames` in the list to an environment of your choice.
As a demonstration, we'll create a new environment (`env`) and create the `data.frame`s in there. In practice, using `.GlobalEnv` would probably be more useful.


```r
ls()
env <- new.env()
ls(env)
```

```
## [1] "bmd_export" "ctu05" "ctu05_raw" "dates"
## [5] "export_location" "factors" "labelled" "labs"
## character(0)
```

```r
Expand All @@ -320,8 +321,8 @@ names(ctu05)
```

```r
as.data.frame(ctu05)
ls()
as.data.frame(ctu05, envir = env)
ls(env)
```

```
Expand All @@ -330,14 +331,10 @@ ls()
## [5] "atmnpctu05allmedi" "atmnpctu05baseline"
## [7] "atmnpctu05outcome" "atmnpctu05sae"
## [9] "atmnpctu05studyterminat" "atmnpctu05treatment"
## [11] "bmd_export" "ctu05"
## [13] "ctu05_raw" "ctu05ae"
## [15] "ctu05allmedi" "ctu05baseline"
## [17] "ctu05outcome" "ctu05sae"
## [19] "ctu05studyterminat" "ctu05treatment"
## [21] "dates" "emnpctu05surgeries"
## [23] "export_location" "factors"
## [25] "labelled" "labs"
## [11] "ctu05ae" "ctu05allmedi"
## [13] "ctu05baseline" "ctu05outcome"
## [15] "ctu05sae" "ctu05studyterminat"
## [17] "ctu05treatment" "emnpctu05surgeries"
```

There are also options for selecting specific forms (option `data.frames`), changing names based on regex (options `regex` and `rep`) and specifying whether metadata objects should be returned (option `meta`).
Expand Down Expand Up @@ -580,13 +577,22 @@ R CMD check secuTrialR_0.9.0.tar.gz
```

### Versioning and releases

The version number is made up of three digits. The first digit
is reserved for major releases which may break backwards compatibility.
The second and third digits are used for medium and minor changes respectively.
Versions released on CRAN will be tagged and saved as releases on GitHub.
The version released on CRAN is regarded as the stable version while
the master branch on GitHub is regarded as the current development version.

#### Release checklist

Compile/Update:
* README.Rmd
* vignette
* pkgdown page
* NEWS.md

### Guidelines for contributors

Requests for new features and bug fixes should first be documented as an [Issue](https://github.com/SwissClinicalTrialOrganisation/secuTrialR/issues) on GitHub.
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5be910e

Please sign in to comment.