diff --git a/DESCRIPTION b/DESCRIPTION index f16ec351..b89aff9d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index 37257e12..594ae604 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/asdataframe.R b/R/asdataframe.R index 67f0391b..577c62b3 100644 --- a/R/asdataframe.R +++ b/R/asdataframe.R @@ -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 @@ -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") @@ -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) ) } diff --git a/README.Rmd b/README.Rmd index 311b1432..60c5798c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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`). @@ -336,6 +338,7 @@ 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. @@ -343,6 +346,14 @@ 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. diff --git a/README.md b/README.md index d9d8a488..520de142 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -# 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/). @@ -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 @@ -320,8 +321,8 @@ names(ctu05) ``` ```r -as.data.frame(ctu05) -ls() +as.data.frame(ctu05, envir = env) +ls(env) ``` ``` @@ -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`). @@ -580,6 +577,7 @@ 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. @@ -587,6 +585,14 @@ 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. diff --git a/docs/404.html b/docs/404.html index 3146fd67..5be56508 100644 --- a/docs/404.html +++ b/docs/404.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 867afb26..f2551aac 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/LICENSE.html b/docs/LICENSE.html index b52c962d..c2267166 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/articles/index.html b/docs/articles/index.html index ad0e31f1..8320e89f 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/articles/secuTrialR-package-vignette.html b/docs/articles/secuTrialR-package-vignette.html index da8d6225..c63c6e96 100644 --- a/docs/articles/secuTrialR-package-vignette.html +++ b/docs/articles/secuTrialR-package-vignette.html @@ -31,7 +31,7 @@ secuTrialR - 1.0.2 + 1.0.3 @@ -78,7 +78,7 @@

secuTrialR - a walkthrough

Patrick R. Wright, Milica Markovic, Alan G. Haynes

-

2020-04-14

+

2020-04-16

@@ -119,7 +119,7 @@

suppressMessages(library(secuTrialR)) # show secuTrialR version packageVersion("secuTrialR") -#> [1] '1.0.2' +#> [1] '1.0.3'

@@ -162,7 +162,7 @@

We have implemented a custom variation of the print() function for secuTrialdata objects.

print(ctu05_data)
 #> secuTrial data imported from:
-#> /tmp/RtmpK0Wr8e/temp_libpath64b41b9c838b/secuTrialR/extdata/sT_exports/exp_opt/
+#> /tmp/RtmpPMLRoa/temp_libpath4a721c7d0d4f/secuTrialR/extdata/sT_exports/exp_opt/
 #> s_export_CSV-xls_CTU05_all_info.zip 
 #>            table nrow ncol  meta       original_name
 #>               vp    4   12  TRUE              vp.xls
@@ -541,7 +541,7 @@ 

Conversion to SPSS, STATA, SAS

Given that you are working with R it is unlikely that you need such conversions for yourself. However, collaborators may ask for data which is readily importable into SPSS, STATA or SAS. For this you can use write_secuTrial().

-

Since this has not been heavily tested or used there may be issues and you might prefer doing this manually with the haven package.

+

Since this has not been heavily tested or used there may be issues and you might prefer doing this manually with the haven package. One particular sticking point is the length of variable names - R is not restrictive in this respect, but other software can be. secuTrialR does not truncate names, prefering to leave this to the user, which can cause write_secuTrial() to fail with an error.

# retrieve path to a temporary directory
 tdir <- tempdir()
 # write spss
@@ -625,42 +625,21 @@ 

The as.data.frame function

This vignette has been working with the secuTrialdata object, which is of type list. For some users, working with a list can be tiresome so secuTrialR provides an as.data.frame() method to save the data.frames in the secuTrialdata object to an environment of your choice.

-

Let’s have a look at the state of your globalenv() before running as.data.frame()

-
ls(globalenv())
-#>  [1] "bl_docids"              "centres"               
-#>  [3] "ctu05_data"             "ctu05_data_berlin"     
-#>  [5] "ctu05_data_bern"        "ctu05_data_bern_basel" 
-#>  [7] "ctu05_data_bern_berlin" "ctu05_data_location"   
-#>  [9] "ctu05_data_pids"        "ctu06_v1"              
-#> [11] "ctu06_v2"               "customer"              
-#> [13] "fsc"                    "fss"                   
-#> [15] "instance"               "links"                 
-#> [17] "participants"           "project"               
-#> [19] "server"                 "vs"
-
# add files to global environment
-as.data.frame(ctu05_data)
+

As an example, we will create an environment called env and check that it’s empty before running as.data.frame()

+
env <- new.env()
+ls(env)
+#> character(0)
+
# add files to env
+as.data.frame(ctu05_data, envir = env)

… and afterwards.

-
ls(globalenv())
-#>  [1] "ae"                     "allmedi"               
-#>  [3] "atae"                   "atae1"                 
-#>  [5] "atallmedi"              "atbaseline"            
-#>  [7] "atesurgeries"           "atmiv"                 
-#>  [9] "atoutcome"              "atsae"                 
-#> [11] "atstudyterminat"        "attreatment"           
-#> [13] "baseline"               "bl_docids"             
-#> [15] "centres"                "ctu05_data"            
-#> [17] "ctu05_data_berlin"      "ctu05_data_bern"       
-#> [19] "ctu05_data_bern_basel"  "ctu05_data_bern_berlin"
-#> [21] "ctu05_data_location"    "ctu05_data_pids"       
-#> [23] "ctu06_v1"               "ctu06_v2"              
-#> [25] "customer"               "esurgeries"            
-#> [27] "fsc"                    "fss"                   
-#> [29] "instance"               "links"                 
-#> [31] "outcome"                "participants"          
-#> [33] "project"                "sae"                   
-#> [35] "server"                 "studyterminat"         
-#> [37] "treatment"              "vs"
-
+
ls(env)
+#>  [1] "ae"              "allmedi"         "atae"           
+#>  [4] "atae1"           "atallmedi"       "atbaseline"     
+#>  [7] "atesurgeries"    "atmiv"           "atoutcome"      
+#> [10] "atsae"           "atstudyterminat" "attreatment"    
+#> [13] "baseline"        "esurgeries"      "outcome"        
+#> [16] "sae"             "studyterminat"   "treatment"
+

Substituting env with .GlobalEnv instead would also be an option and would make the data.frames immediately accessible without having to refer to an environment.

@@ -725,7 +704,7 @@

#> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: -#> [1] secuTrialR_1.0.2 +#> [1] secuTrialR_1.0.3 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_1.0.3 cellranger_1.1.0 compiler_3.6.3 pillar_1.4.2 diff --git a/docs/authors.html b/docs/authors.html index 12893993..93a9926a 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3

diff --git a/docs/index.html b/docs/index.html index 2e5b0aa9..9db1aa44 100644 --- a/docs/index.html +++ b/docs/index.html @@ -34,7 +34,7 @@ secuTrialR - 1.0.2 + 1.0.3
@@ -79,7 +79,7 @@

An R package to handle data from the clinical data management system (CDMS) secuTrial.

@@ -255,10 +255,10 @@

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.

-
ls()
-
## [1] "bmd_export"      "ctu05"           "ctu05_raw"       "dates"          
-## [5] "export_location" "factors"         "labelled"        "labs"
+

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.frames in there. In practice, using .GlobalEnv would probably be more useful.

+
env <- new.env()
+ls(env)
+
## character(0)
names(ctu05)
##  [1] "export_options"          "forms"                  
 ##  [3] "casenodes"               "centres"                
@@ -276,21 +276,17 @@ 

## [27] "atmnpctu05ae" "ctu05sae" ## [29] "atmnpctu05sae" "emnpctu05surgeries" ## [31] "atemnpctu05surgeries" "atadverseevents"

-
as.data.frame(ctu05)
-ls()
+
as.data.frame(ctu05, envir = env)
+ls(env)
##  [1] "atadverseevents"         "atemnpctu05surgeries"   
 ##  [3] "atmiv"                   "atmnpctu05ae"           
 ##  [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).

@@ -476,6 +472,17 @@

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
  • +
+

diff --git a/docs/news/index.html b/docs/news/index.html index 09636f80..5203fd7c 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3

@@ -121,9 +121,9 @@

Changelog

-
+

-secuTrialR 1.0.1, 1.0.2

+secuTrialR 1.0.1, 1.0.2, 1.0.3

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 4a5d4b9b..7c862b4e 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 1.5.0 pkgdown_sha: ~ articles: secuTrialR-package-vignette: secuTrialR-package-vignette.html -last_built: 2020-04-14T11:08Z +last_built: 2020-04-16T15:11Z diff --git a/docs/reference/annual_recruitment.html b/docs/reference/annual_recruitment.html index 508bedde..b5374120 100644 --- a/docs/reference/annual_recruitment.html +++ b/docs/reference/annual_recruitment.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3
diff --git a/docs/reference/as.data.frame.secuTrialdata.html b/docs/reference/as.data.frame.secuTrialdata.html index c92e9cf8..b6cf2a61 100644 --- a/docs/reference/as.data.frame.secuTrialdata.html +++ b/docs/reference/as.data.frame.secuTrialdata.html @@ -6,7 +6,11 @@ -as.data.frame method for secuTrialdata objects — as.data.frame.secuTrialdata • secuTrialR +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</code>) and you can reference them without referring to the +<code>secuTrialdata</code> object anymore. Ie. they become regular <code>data.frame</code>s). — as.data.frame.secuTrialdata • secuTrialR @@ -39,8 +43,16 @@ - - + + @@ -72,7 +84,7 @@ secuTrialR - 1.0.2 + 1.0.3 @@ -118,24 +130,32 @@
-

as.data.frame method for secuTrialdata objects

+

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 +(.GlobalEnv) and you can reference them without referring to the +secuTrialdata object anymore. Ie. they become regular data.frames).

# S3 method for secuTrialdata
 as.data.frame(
   x,
   ...,
+  envir,
   data.frames = NULL,
   meta = FALSE,
   regex = NULL,
-  rep = "",
-  envir = .GlobalEnv
+  rep = ""
 )

Arguments

@@ -149,6 +169,10 @@

Arg ...

further parameters

+ + envir +

environment in which to put the data (e.g. .GlobalEnv)

+ data.frames

character vector of data.frame names to turn into data.frames

@@ -165,15 +189,17 @@

Arg rep

replacement for regex

- - envir -

environment in which to put the data

-

Value

-

each data.frame on the secuTrialdata object is saved to it's own data.frame in the environment

+

each data.frame in the secuTrialdata object is saved to it's +own data.frame in the designated environment

+

Details

+ +

envir must be specifically defined. For simplicity, +.GlobalEnv would probably be the easiest (assigning it to another +environment would still entail referring to that environment).

Examples

# prepare path to example export @@ -182,10 +208,13 @@

Examp 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")

+# 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)
diff --git a/docs/reference/build_secuTrial_url.html b/docs/reference/build_secuTrial_url.html index 632b4577..336fe93d 100644 --- a/docs/reference/build_secuTrial_url.html +++ b/docs/reference/build_secuTrial_url.html @@ -73,7 +73,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/check_export_options.html b/docs/reference/check_export_options.html index 7967f63f..8fc4e321 100644 --- a/docs/reference/check_export_options.html +++ b/docs/reference/check_export_options.html @@ -73,7 +73,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/dates_secuTrial.html b/docs/reference/dates_secuTrial.html index edeb5441..6a6ded89 100644 --- a/docs/reference/dates_secuTrial.html +++ b/docs/reference/dates_secuTrial.html @@ -72,7 +72,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/diff_secuTrial.html b/docs/reference/diff_secuTrial.html index 4fc11329..806ff48f 100644 --- a/docs/reference/diff_secuTrial.html +++ b/docs/reference/diff_secuTrial.html @@ -80,7 +80,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/factorize.html b/docs/reference/factorize.html index 0b16016a..de2edf2e 100644 --- a/docs/reference/factorize.html +++ b/docs/reference/factorize.html @@ -76,7 +76,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/form_status_counts.html b/docs/reference/form_status_counts.html index 010373eb..50a93ca7 100644 --- a/docs/reference/form_status_counts.html +++ b/docs/reference/form_status_counts.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/form_status_summary.html b/docs/reference/form_status_summary.html index f3a104b5..c87a4520 100644 --- a/docs/reference/form_status_summary.html +++ b/docs/reference/form_status_summary.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/get_participants.html b/docs/reference/get_participants.html index 1f166148..2ffbe922 100644 --- a/docs/reference/get_participants.html +++ b/docs/reference/get_participants.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/index.html b/docs/reference/index.html index b0fb5698..22cd8f55 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -71,7 +71,7 @@ secuTrialR - 1.0.2 + 1.0.3 @@ -151,7 +151,11 @@

as.data.frame(<secuTrialdata>)

-

as.data.frame method for secuTrialdata objects

+

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 +(.GlobalEnv) and you can reference them without referring to the +secuTrialdata object anymore. Ie. they become regular data.frames).

diff --git a/docs/reference/labels_secuTrial.html b/docs/reference/labels_secuTrial.html index d868cb20..bde0a66e 100644 --- a/docs/reference/labels_secuTrial.html +++ b/docs/reference/labels_secuTrial.html @@ -75,7 +75,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/links_secuTrial.html b/docs/reference/links_secuTrial.html index 090e401f..70452694 100644 --- a/docs/reference/links_secuTrial.html +++ b/docs/reference/links_secuTrial.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/plot_recruitment.html b/docs/reference/plot_recruitment.html index e42f27e4..9a396cff 100644 --- a/docs/reference/plot_recruitment.html +++ b/docs/reference/plot_recruitment.html @@ -75,7 +75,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/read_secuTrial.html b/docs/reference/read_secuTrial.html index c2841fcd..2eed8eac 100644 --- a/docs/reference/read_secuTrial.html +++ b/docs/reference/read_secuTrial.html @@ -73,7 +73,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/read_validation_overview.html b/docs/reference/read_validation_overview.html index 04d3e6ec..30d6304d 100644 --- a/docs/reference/read_validation_overview.html +++ b/docs/reference/read_validation_overview.html @@ -72,7 +72,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/return_hidden_items.html b/docs/reference/return_hidden_items.html index b0ef2786..da0205f7 100644 --- a/docs/reference/return_hidden_items.html +++ b/docs/reference/return_hidden_items.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/return_random_participants.html b/docs/reference/return_random_participants.html index de5b76fa..4802f83a 100644 --- a/docs/reference/return_random_participants.html +++ b/docs/reference/return_random_participants.html @@ -73,7 +73,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/return_scores.html b/docs/reference/return_scores.html index 38b6e95c..c1904fe0 100644 --- a/docs/reference/return_scores.html +++ b/docs/reference/return_scores.html @@ -75,7 +75,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/secuTrialdata.html b/docs/reference/secuTrialdata.html index b5d38860..908922e2 100644 --- a/docs/reference/secuTrialdata.html +++ b/docs/reference/secuTrialdata.html @@ -73,7 +73,7 @@ secuTrialR - 1.0.2 + 1.0.3 @@ -172,7 +172,7 @@

Examp # Print method print(sT_export)
#> secuTrial data imported from: -#> /tmp/RtmpK0Wr8e/temp_libpath64b41b9c838b/secuTrialR/extdata/sT_exports/BMD/ +#> /tmp/RtmpPMLRoa/temp_libpath4a721c7d0d4f/secuTrialR/extdata/sT_exports/BMD/ #> s_export_CSV-xls_BMD_short_en_utf8.zip #> table nrow ncol meta original_name #> vp 1 10 TRUE vp.xls @@ -189,7 +189,7 @@

Examp #> bmd 504 27 FALSE bmd.xls #> atbmd 0 28 FALSE atbmd.xls

# or sT_export
#> secuTrial data imported from: -#> /tmp/RtmpK0Wr8e/temp_libpath64b41b9c838b/secuTrialR/extdata/sT_exports/BMD/ +#> /tmp/RtmpPMLRoa/temp_libpath4a721c7d0d4f/secuTrialR/extdata/sT_exports/BMD/ #> s_export_CSV-xls_BMD_short_en_utf8.zip #> table nrow ncol meta original_name #> vp 1 10 TRUE vp.xls diff --git a/docs/reference/subset_secuTrial.html b/docs/reference/subset_secuTrial.html index 7e563091..d30bd188 100644 --- a/docs/reference/subset_secuTrial.html +++ b/docs/reference/subset_secuTrial.html @@ -76,7 +76,7 @@ secuTrialR - 1.0.2 + 1.0.3
diff --git a/docs/reference/visit_structure.html b/docs/reference/visit_structure.html index 0c98d6d8..0d940527 100644 --- a/docs/reference/visit_structure.html +++ b/docs/reference/visit_structure.html @@ -72,7 +72,7 @@ secuTrialR - 1.0.2 + 1.0.3 diff --git a/docs/reference/write_secuTrial.html b/docs/reference/write_secuTrial.html index b53cf1a1..3f793d26 100644 --- a/docs/reference/write_secuTrial.html +++ b/docs/reference/write_secuTrial.html @@ -74,7 +74,7 @@ secuTrialR - 1.0.2 + 1.0.3 @@ -192,58 +192,58 @@

Examp sT_export <- read_secuTrial(data_dir = export_location)
#> Read export successfully.
#> The following export options deviate from the suggested specifications: #> Data from hidden fields is part of the export.
tdir <- tempdir() write_secuTrial(sT_export, format = "dta", path = tdir)
#> [[1]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmiv.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmiv.dta" #> #> [[2]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05baseline.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05baseline.dta" #> #> [[3]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05baseline.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05baseline.dta" #> #> [[4]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05outcome.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05outcome.dta" #> #> [[5]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05outcome.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05outcome.dta" #> #> [[6]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05treatment.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05treatment.dta" #> #> [[7]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05treatment.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05treatment.dta" #> #> [[8]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05allmedi.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05allmedi.dta" #> #> [[9]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05allmedi.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05allmedi.dta" #> #> [[10]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05studyterminat.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05studyterminat.dta" #> #> [[11]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05studyterminat.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05studyterminat.dta" #> #> [[12]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05ae.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05ae.dta" #> #> [[13]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05ae.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05ae.dta" #> #> [[14]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/ctu05sae.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/ctu05sae.dta" #> #> [[15]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atmnpctu05sae.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atmnpctu05sae.dta" #> #> [[16]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/emnpctu05surgeries.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/emnpctu05surgeries.dta" #> #> [[17]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atemnpctu05surgeries.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atemnpctu05surgeries.dta" #> #> [[18]] -#> [1] "Saved to /tmp/Rtmp0EgKXY/atadverseevents.dta" +#> [1] "Saved to /tmp/RtmpxggMmL/atadverseevents.dta" #>
list.files(tdir)
#> [1] "atadverseevents.dta" "atemnpctu05surgeries.dta" #> [3] "atmiv.dta" "atmnpctu05ae.dta" #> [5] "atmnpctu05allmedi.dta" "atmnpctu05baseline.dta" @@ -253,8 +253,8 @@

Examp #> [13] "ctu05baseline.dta" "ctu05outcome.dta" #> [15] "ctu05sae.dta" "ctu05studyterminat.dta" #> [17] "ctu05treatment.dta" "emnpctu05surgeries.dta" -#> [19] "file656f296c7e9e.so" "libloc_169_8f48fc7d1db1bb3e.rds" -#> [21] "libloc_174_173b0d0583319ed2.rds" "libloc_191_4cc1d5364175653b.rds" +#> [19] "file4b385ad1489b.so" "libloc_169_8f48fc7d1db1bb3e.rds" +#> [21] "libloc_174_173b0d0583319ed2.rds" "libloc_191_d32425051badb81e.rds" #> [23] "libloc_198_906ea0066f46c4fa.rds"

diff --git a/man/as.data.frame.secuTrialdata.Rd b/man/as.data.frame.secuTrialdata.Rd index ec0101c3..f45f9ef7 100644 --- a/man/as.data.frame.secuTrialdata.Rd +++ b/man/as.data.frame.secuTrialdata.Rd @@ -2,16 +2,20 @@ % Please edit documentation in R/asdataframe.R \name{as.data.frame.secuTrialdata} \alias{as.data.frame.secuTrialdata} -\title{as.data.frame method for secuTrialdata objects} +\title{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).} \usage{ \method{as.data.frame}{secuTrialdata}( x, ..., + envir, data.frames = NULL, meta = FALSE, regex = NULL, - rep = "", - envir = .GlobalEnv + rep = "" ) } \arguments{ @@ -19,6 +23,8 @@ \item{...}{further parameters} +\item{envir}{environment in which to put the data (e.g. \code{.GlobalEnv})} + \item{data.frames}{character vector of data.frame names to turn into data.frames} \item{meta}{logical should metadata be returned} @@ -26,14 +32,22 @@ \item{regex}{regex syntax to remove from names} \item{rep}{replacement for regex} - -\item{envir}{environment in which to put the data} } \value{ -each data.frame on the \code{secuTrialdata} object is saved to it's own data.frame in the environment +each \code{data.frame} in the \code{secuTrialdata} object is saved to it's +own \code{data.frame} in the designated environment } \description{ 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). +} +\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). } \examples{ # prepare path to example export @@ -42,8 +56,11 @@ export_location <- system.file("extdata", "sT_exports", "lnames", 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") +# 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) } diff --git a/tests/testthat/test-asdataframe.R b/tests/testthat/test-asdataframe.R index d46d9e81..835c4f73 100644 --- a/tests/testthat/test-asdataframe.R +++ b/tests/testthat/test-asdataframe.R @@ -10,23 +10,26 @@ test_that("bmd", { test <- new.env() - expect_error(as.data.frame(bmd), regexp = NA) + expect_error(as.data.frame(bmd, envir = .GlobalEnv), regexp = NA) expect_true(exists("dem00bmd")) expect_equal(dem00bmd, bmd$dem00bmd) expect_false(any(sapply(c("forms", "casenodes", "centres", "items"), exists))) - expect_error(as.data.frame(bmd, regex = "em00"), regexp = NA) + expect_error(as.data.frame(bmd, regex = "em00", + envir = .GlobalEnv), regexp = NA) expect_equal(dbmd, bmd$dem00bmd) expect_true(exists("dbmd")) - expect_error(as.data.frame(bmd, regex = "m00", meta = TRUE), regexp = NA) + expect_error(as.data.frame(bmd, regex = "m00", meta = TRUE, + envir = .GlobalEnv), regexp = NA) expect_equal(debmd, bmd$dem00bmd) expect_true(exists("debmd")) expect_true(all(sapply(c("forms", "casenodes", "centres", "items"), exists))) expect_error(as.data.frame(bmd, regex = "dem00", rep = "foo", - data.frames = c("dem00bmd")), regexp = NA) + data.frames = c("dem00bmd"), + envir = .GlobalEnv), regexp = NA) expect_equal(foobmd, bmd$dem00bmd) expect_true(exists("foobmd")) expect_false(exists("atmnpfoobmd")) @@ -39,19 +42,20 @@ test_that("bmd", { }) test_that("errors", { - expect_error(as.data.frame(bmd, data.frames = "foo"), + expect_error(as.data.frame(bmd, data.frames = "foo", envir = .GlobalEnv), regexp = "unrecognised data.frame specified") - expect_error(as.data.frame(bmd, regex = TRUE), + expect_error(as.data.frame(bmd, regex = TRUE, envir = .GlobalEnv), regexp = "regex should be either NULL or character") - expect_warning(as.data.frame(bmd, regex = c("a", "b")), + expect_warning(as.data.frame(bmd, regex = c("a", "b"), envir = .GlobalEnv), regexp = "argument 'pattern' has length > 1") - expect_error(as.data.frame(bmd, rep = TRUE), + expect_error(as.data.frame(bmd, rep = TRUE, envir = .GlobalEnv), regexp = "rep should be character") - expect_warning(as.data.frame(bmd, regex = c("a", "b"), rep = c("c", "d")), + expect_warning(as.data.frame(bmd, regex = c("a", "b"), rep = c("c", "d"), + envir = .GlobalEnv), regexp = "argument 'replacement' has length > 1") expect_error(as.data.frame(bmd, envir = TRUE), diff --git a/vignettes/secuTrialR-package-vignette.Rmd b/vignettes/secuTrialR-package-vignette.Rmd index fe97e63f..32378e5e 100644 --- a/vignettes/secuTrialR-package-vignette.Rmd +++ b/vignettes/secuTrialR-package-vignette.Rmd @@ -505,7 +505,10 @@ yourself. However, collaborators may ask for data which is readily importable in STATA or SAS. For this you can use `write_secuTrial()`. Since this has not been heavily tested or used there may be issues and -you might prefer doing this manually with the `haven` package. +you might prefer doing this manually with the `haven` package. One particular +sticking point is the length of variable names - R is not restrictive in this +respect, but other software can be. `secuTrialR` does not truncate names, prefering +to leave this to the user, which can cause `write_secuTrial()` to fail with an error. \vspace{5pt} ```{r, eval = FALSE} @@ -631,26 +634,27 @@ For some users, working with a `list` can be tiresome so `secuTrialR` provides a `as.data.frame()` method to save the `data.frame`s in the `secuTrialdata` object to an environment of your choice. -Let's have a look at the state of your `globalenv()` +As an example, we will create an environment called `env` and check that it's empty before running `as.data.frame()`... \vspace{5pt} ```{r} -ls(globalenv()) +env <- new.env() +ls(env) ``` ```{r} -# add files to global environment -as.data.frame(ctu05_data) +# add files to env +as.data.frame(ctu05_data, envir = env) ``` ... and afterwards. \vspace{5pt} ```{r} -ls(globalenv()) +ls(env) ``` -\newpage +Substituting `env` with `.GlobalEnv` instead would also be an option and would make the data.frames immediately accessible without having to refer to an environment. # Frequent warning messages diff --git a/vignettes/secuTrialR-package-vignette.pdf b/vignettes/secuTrialR-package-vignette.pdf index 3899de07..4bb5e16a 100644 Binary files a/vignettes/secuTrialR-package-vignette.pdf and b/vignettes/secuTrialR-package-vignette.pdf differ