Unverified Commit 273bee35 authored by Cody L Marquart's avatar Cody L Marquart
Browse files

Merge branch 'develop'

parents 86fdf86d b0eaeb5b
Pipeline #49507 failed with stages
in 5 minutes and 55 seconds
......@@ -7,17 +7,25 @@ stages:
- release
variables:
VERSION: "0.2.0.0"
VERSION: "0.2.0.1"
PKG: "ncodeR"
PKGL: "ncoder"
REG_URL: "${CI_REGISTRY}/epistemic-analytics/qe-packages/ncoder"
# Templates
.check_condition: &check_condition
except:
refs:
- tags
variables:
- $CI_COMMIT_MESSAGE =~ /.*\[skip check\].*/
.build_definition: &build_template
before_script:
- export _R_CHECK_CRAN_INCOMING_=FALSE
- export _R_CHECK_FORCE_SUGGESTS_=TRUE
- mkdir -p archive/
- "sed -i -e \"s/Version: \\(.*\\)/Version: ${VERSION}/\" DESCRIPTION"
- cat DESCRIPTION
- Rscript -e 'update(devtools::dev_package_deps("."))'
- Rscript -e 'install.packages("knitr")'
- Rscript -e 'install.packages("rmarkdown")'
......@@ -36,54 +44,56 @@ variables:
script:
- R --no-site-file --no-environ --no-save --no-restore --quiet CMD check ${PKG}_${VERSION}.tar.gz --as-cran --no-manual
- ls -al ./
- ls -al ./$PKG.Rcheck/
- ls -al ./$PKG.Rcheck/ || true
- mv ./$PKG-00build.log $PKG/archive/ || true
- mv ./$PKG.Rcheck/00check.log $PKG/archive/ || true
- mv ./$PKG.Rcheck/00install.out $PKG/archive/ || true
- mv ./${PKG}_${VERSION}.tar.gz $PKG/archive/
tags:
- docker
- "grep -v -e 'STATUS:.*ERROR' -e 'STATUS:.*WARNING' ${PKG}/archive/00check.log && echo $? || echo $?"
allow_failure: false
<<: *check_condition
# Check Steps
check:r-devel:
image: $REG_URL/devel:current
only:
refs:
- master
- tags
<<: *check_template
check:r-oldrelease:
image: $REG_URL/oldrelease:current
only:
refs:
- master
- tags
<<: *check_template
check:r-release:
image: $REG_URL/release:current
only:
refs:
- master
- tags
<<: *check_template
check:r-winbuilder:
stage: checkWindows
image: egruw/r-ftp
.rhub_definition: &rhub_definition
stage: check
image: $REG_URL/release:current
before_script:
- Rscript -e 'install.packages("rhub")'
script:
- |
Rscript -e "rhub::validate_email(email = \"${RHUB_EMAIL_ADDRESS}\", token = \"${RHUB_EMAIL_TOKEN}\");
checked <- rhub::check(platform = \"${RHUB_PLATFORM}\", show_status = TRUE);
checked\$cran_summary();
quit(status = ifelse(!checked\$.__enclos_env__\$private\$status_[[1]]\$status %in% c('error', 'warning'), 0, 1));"
only:
refs:
- master
- tags
when: manual
<<: *build_template
script:
- curl -v -T ${PKG}_${VERSION}.tar.gz ftp://win-builder.r-project.org/R-oldrelease/${PKG}_${VERSION}.tar.gz
- curl -v -T ${PKG}_${VERSION}.tar.gz ftp://win-builder.r-project.org/R-release/${PKG}_${VERSION}.tar.gz
- curl -v -T ${PKG}_${VERSION}.tar.gz ftp://win-builder.r-project.org/R-devel/${PKG}_${VERSION}.tar.gz
- mv ./${PKG}_${VERSION}.tar.gz $PKG/archive/
tags:
- docker
allow_failure: false
variables:
- $RHUB_EMAIL_ADDRESS
- $RHUB_EMAIL_TOKEN
<<: *check_condition
check:r-hub-windows-old-release:
variables:
RHUB_PLATFORM: "windows-x86_64-oldrel"
<<: *rhub_definition
check:r-hub-windows-release:
variables:
RHUB_PLATFORM: "windows-x86_64-release"
<<: *rhub_definition
check:r-hub-windows-devel:
variables:
RHUB_PLATFORM: "windows-x86_64-devel"
<<: *rhub_definition
release:cran:
stage: release
......@@ -106,6 +116,7 @@ test:r-release:
stage: test
image: $REG_URL/release-test:current
script:
- "sed -i -e \"s/Version: \\(.*\\)/Version: ${VERSION}/\" DESCRIPTION"
- 'Rscript -e "Rcpp::compileAttributes()"'
- 'Rscript -e "rep <- covr::report( x = covr::package_coverage(quiet = T), file = \"inst/coverage/${CI_COMMIT_REF_NAME}/index.html\" )"'
- 'Rscript -e "setwd(\"inst/coverage/${CI_COMMIT_REF_NAME}\"); res = lapply(dir(\".\", full.names = F, recursive = T), function(f) { aws.s3::put_object(file = f, object = paste0(\"coverage/${CI_COMMIT_REF_NAME}/\", f), bucket = \"${PKGL}.qe-libs.org\", acl = \"public-read\") })"'
......@@ -119,6 +130,7 @@ docs:build-site:
script:
- rm -rf src/RcppExports*
- rm -rf R/RcppExports*
- "sed -i -e \"s/Version: \\(.*\\)/Version: ${VERSION}/\" DESCRIPTION"
- 'Rscript -e "Rcpp::compileAttributes()"'
- 'Rscript -e "install.packages(\"fs\")"'
- 'Rscript -e "install.packages(\"pkgdown\")"'
......@@ -128,6 +140,10 @@ docs:build-site:
dependencies:
- test:r-release
.docker_variables: &docker_variables
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
.docker_definition: &docker_template
stage: docker
image: docker:19.03.1
......@@ -138,13 +154,14 @@ docs:build-site:
script:
- docker build -t $REG_URL/$TAG:current -f inst/docker/$PKG-$FILE inst/docker/
- docker push $REG_URL/$TAG:current
only:
variables:
- $CI_COMMIT_MESSAGE =~ /.*\[build docker\].*/ || $DOCKER_FORCE_REBUILD
docker:release:
variables:
TAG: "release"
FILE: "release"
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
<<: *docker_variables
only:
refs:
- branches
......@@ -157,52 +174,19 @@ docker:release:
<<: *docker_template
docker:release-test:
variables:
<<: *docker_variables
TAG: "release-test"
FILE: "release-test"
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
only:
refs:
- branches
changes:
- "inst/docker/$PKG-$FILE"
except:
refs:
- master
- tags
<<: *docker_template
docker:old-release:
variables:
<<: *docker_variables
TAG: "oldrelease"
FILE: "oldrelease"
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
only:
refs:
- branches
changes:
- "inst/docker/$PKG-$FILE"
except:
refs:
- master
- tags
<<: *docker_template
docker:devel:
variables:
<<: *docker_variables
TAG: "devel"
FILE: "devel"
DOCKER_HOST: tcp://localhost:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
only:
refs:
- branches
changes:
- "inst/docker/$PKG-$FILE"
except:
refs:
- master
- tags
<<: *docker_template
\ No newline at end of file
......@@ -29,11 +29,12 @@ as.data.frame.CodeSet <- function(x, row.names = NULL, optional = FALSE, ...) {
if(is.null(len) && !is.null(args$len)) len = args$len;
if(is.null(args$codes)) codes = x$codes;
if(!is.null(len) && len > 0) {
data.frame(ID = 1:len, excerpt = excerpts[1:len], sapply(codes, function(x){
coded_cols <- sapply(codes, function(x){
df = data.frame( x$computerSet[1:len] )
colnames(df) = c( x[['name']] )
df
}))
})
names(coded_cols) <- as.character(lapply(codes, `[[`, "name"))
data.frame(ID = 1:len, excerpt = excerpts[1:len], coded_cols)
} else {
data.frame()
}
......
FROM rocker/r-ver:3.4.4
FROM rocker/r-ver:3.5.3
RUN apt-get update -y
RUN apt-get install -y apt-utils
......
FROM rocker/r-ver:latest
RUN apt-get update -y
RUN apt-get install -y apt-utils
RUN apt-get install -y libxml2 xml2
......
#FROM rocker/r-ver:latest
FROM registry.doit.wisc.edu/epistemic-analytics/qe-packages/ncoder/release:current
FROM rocker/r-ver:latest
RUN apt-get update -y
RUN apt-get install -y apt-utils
RUN apt-get install -y libxml2 xml2
RUN apt-get install -y libxml2-dev
RUN apt-get install -y libcurl4-openssl-dev libssh2-1-dev libssl-dev git
RUN apt-get install -y qpdf pandoc pandoc-citeproc openssh-client curl
RUN apt-cache search git
RUN apt-get install -y libgit2-dev
RUN R -e 'install.packages(c("roxygen2"), repos="http://cran.rstudio.com")'
RUN R -e 'install.packages(c("git2r","usethis","devtools","testthat"), repos="http://cran.rstudio.com")'
RUN R -e 'install.packages(c("R6","rhoR","cli"), repos="http://cran.rstudio.com")'
### Steps needed for testing the package and storing files
RUN R -e 'install.packages(c("covr", "DT"), repos="http://cran.rstudio.com")'
RUN R -e 'install.packages(c("aws.s3","aws.signature"), repos="http://cran.rstudio.com")'
RUN pwd
RUN R -e 'install.packages(c("fs"), repos="http://cran.rstudio.com")'
RUN pwd
RUN R -e 'install.packages(c("pkgdown"), repos="http://cran.rstudio.com")'
RUN R -e 'install.packages(c("aws.s3","aws.signature"), repos="http://cran.rstudio.com")'
......
library(testthat)
context("Testing the autocode function")
data(RS.data)
rs_text = RS.data$text
test_that("test autocoding code set", {
code.data = create.code(name = "Data", expressions = c("number","data"), excerpts = rs_text)
code.people = create.code(name = "People", expressions = c("people","he", "she", "they"), excerpts = rs_text)
code.set = code.set("Demo RS CodeSet", "CodeSet made for the demo", codes = c(code.data, code.people))
allcoded = autocode(x = code.set, excerpts = rs_text, simplify = TRUE)
expect_equivalent(colnames(allcoded), c("ID", "excerpt", "Data", "People"))
expect_equal(nrow(allcoded), length(rs_text))
expect_true(all(allcoded$Data %in% c(0, 1)))
expect_true(all(allcoded$People %in% c(0, 1)))
})
test_that("test autocoding single code", {
code.data = create.code(name = "Data", expressions = c("number","data"), excerpts = rs_text)
allcoded = autocode(x = code.data, excerpts = rs_text, simplify = TRUE)
expect_equivalent(colnames(allcoded), c("ID", "excerpt", "Data"))
expect_equal(nrow(allcoded), length(rs_text))
expect_true(all(allcoded$Data %in% c(0, 1)))
})
......@@ -90,3 +90,33 @@ testthat::test_that("Verify clearing of test set", {
expect_equal(newcode_w_training$trainingSet, newcode$testSet)
})
testthat::test_that("Calculate precision and recall", {
name <- "Data"
set <- 10:15
exprs <- c("number","priority")
coded <- sapply(rs_text[set], grepl, pattern = paste0(exprs, collapse = "|")) * 1
newcode <- create.code(name, expressions = exprs, excerpts = rs_text) %>%
handcode(this.set = set, results = 0) %>%
test()
testthat::expect_equal(newcode$statistics[[1]]$one_v_classifier$test_set$recall, 0)
testthat::expect_true(is.nan(newcode$statistics[[1]]$one_v_classifier$test_set$precision))
newcode2 <- create.code(name, expressions = exprs, excerpts = rs_text) %>%
handcode(this.set = set, results = c(rep(0, 5), 1)) %>%
test()
testthat::expect_equal(newcode2$statistics[[1]]$one_v_classifier$test_set$recall, 1)
testthat::expect_equal(newcode2$statistics[[1]]$one_v_classifier$test_set$precision, 1)
newcode3 <- create.code(name, expressions = exprs, excerpts = rs_text) %>%
handcode(this.set = 10:30, results = c(rep(0, 5),1, rep(0,10),1,1,1,0,0) ) %>%
test()
testthat::expect_equal(newcode3$statistics[[1]]$one_v_classifier$test_set$recall, 1)
testthat::expect_equal(newcode3$statistics[[1]]$one_v_classifier$test_set$precision, 0.75)
newcode4 <- create.code(name, expressions = exprs, excerpts = rs_text) %>%
handcode(this.set = 10:30, results = c(rep(0, 5),1, rep(0,10),1,0,0,0,0) ) %>%
test()
testthat::expect_equal(round(newcode4$statistics[[1]]$one_v_classifier$test_set$recall, 2), 0.67)
testthat::expect_equal(newcode4$statistics[[1]]$one_v_classifier$test_set$precision, 1)
})
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment