Testthat package testing Phuse Non-clinical Scripts

Slides:



Advertisements
Similar presentations
Prepared by Abdullah Mueen and Eamonn Keogh
Advertisements

CIS 240 Introduction to UNIX Instructor: Sue Sampson.
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Mello-Dee Simmons Liza Klosterman.  Who We Are ‣Largest community-owned utility in Florida and the eighth largest in the United States. ‣Electric system.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Matlab Software To Do Analyses as in Marron’s Talks Matlab Available from UNC Site License Download Software: Google “Marron Software”
© Lloyd’s 1 © Lloyd’s 1 Sharing Data Analysis Between R and non-R Users.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
ATM 315 Environmental Statistics Course Goto Follow the link and then choose the desktop application.
Downloading & Installing Software Chapter 13. Maintaining the System Yum Pirut BitTiorrent Rpm Keeping Software Up To Date Up2date Red Hat Network Wget.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Working Out with KURL! Shayne Koestler Kinetic Data.
Trilinos 101: Getting Started with Trilinos November 7, :30-9:30 a.m. Mike Heroux Jim Willenbring.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
The EPIKH Project (Exchange Programme to advance e-Infrastructure Know-How) WMPROXY API Python & C++ Diego Scardaci
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
Introduction to R Part 2. Working Directory The working directory is where you are currently saving data in R. What is the current working directory?
DTIAtlasBuilder Adrien Kaiser Neuro Image Research and Analysis Laboratories University of North Carolina at Chapel Hill A tool to create an atlas from.
Testing Especially Unit Testing. V-model Wikipedia:
Renesas Technology America Inc. 1 SKP8CMINI Tutorial 2 Creating A New Project Using HEW.
MOBILE6 On-Road Motor Vehicle Emissions Model 5-Day Training Course Presented in Seattle the week of September 10, 2001 U.S. Environmental Protection Agency.
Installing CompuCell3D from source Maciej Swat Biocomplexity Institute, Indiana University.
CEN 5070 – Software V&V Automation for Program Testing © , E.L. Jones.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Troubleshooting Security Issues Lesson 6. Skills Matrix Technology SkillObjective Domain SkillDomain # Monitoring and Troubleshooting with Event Viewer.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Parsing BLAST output. Output of a local BLAST search “less” program Full path to the BLAST output file.
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
Renesas Technology America Inc. 1 SKP8CMINI Tutorial 2 Creating A New Project Using HEW.
Bioinformatics for biologists
Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.
Assigning Values 1. $ set One Two Three [Enter] $echo $1 $2 $3 [Enter] 2. $set `date` [Enter] $echo $1 $2 $3 [Enter] 3. $echo $1 $2 $3 $4 $5 $6 [Enter]
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
EGEE is a project funded by the European Union under contract IST Installation and configuration of gLite services Robert Harakaly, CERN,
16BIT IITR Data Collection Module If you have not already done so, download and install R from download.
I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)
BIT 285: ( Web) Application Programming Lecture 07 : Tuesday, January 27, 2015 Git.
9/21/04 James Gallagher Server Installation and Testing: Hands-on ● Install the CGI server with the HDF and FreeForm handlers ● Link data so the server.
Bulk Loading Documents* into Windchill
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
Block 1: Introduction to R
Automatic Documentation Systems
METAL Practical You have ran a GWA analysis.
NEMO – Reformating tool
CS 330 Class 7 Comments on Exam Programming plan for today:
Packaging a Structural Biology Application – imod / 3dmod
OCTOPUS – SeaDataNet Format conversion tool
Bulk Loading Documents* into Windchill
Step 1: Download R and install R:
Installing R and R Studio
National Scientific Library at Tbilisi State University
Script Metadata for Sharing
Lab 1 Introductions to R Sean Potter.
WEB PROGRAMMING JavaScript.
Code is on the Website Outline Comparison of Excel and R
Exploring the Power of EPDM Tasks - Working with and Developing Tasks in EPDM By: Marc Young XLM Solutions
This is where R scripts will load
Devtools and package building Phuse Non-clinical Scripts
Introduction to javadoc
Section 4: Graphs and Testing
MIS2502: Data Analytics ICA #7 Introduction to R and RStudio - Recap
Practical work on NetCDF - CFPOINT
This is where R scripts will load
Travel Expenses Tool Instruction Manual
DocumentParser: November, 2013.
Carthage ios 8 onwards Dependency manager that streamlines the process of integrating the libraries into the project.
Introduction to Bash Programming, part 3
Selenium IDE Installation and Use.
AtlasSetup & Evolution
Presentation transcript:

Testthat package testing Phuse Non-clinical Scripts

Prerequisites install.packages("roxygen2") install.packages("devtools") install.packages("testthat") Download and install Rtools 3.4 from http://cran.r-project.org/bin/windows/Rtools/

Devtools workflow for package: library(devtools) build() install() document() test() Will run the “testthat” test case files, from tests subdirect. To get the pdf manual: check(cleanup = FALSE,manual = TRUE,path = getwd()) http://kbroman.org/pkg_primer/pages/docs.html

Rstudio New project – From Build pulldown Create project from existing directory From Build pulldown Build and reload -> does compile,loading Test -> runs the testthat scripts Check -> does build, testthat and checks documentation

Rstudio

Rstudio – check of parsedate Results: Undocumented arguments in documentation object 'dur_to_seconds' 'input' Documented arguments not in \usage in documentation object 'dur_to_seconds': 'date' checking package dependencies ... NOTE Package suggested but not available for checking: 'covr'

Rstudio – check of parsedate Remedied: Changed from: #' @param date The date(s) to format. To #' @param input The date(s) to format. install.packages("covr")

Parsedate – tests directory “testthat” test case files http://kbroman.org/pkg_primer/pages/docs.html

Testthat test cases “Test” from Build pulldown: ==> devtools::test() Loading parsedate Loading required package: testthat Testing parsedate Dates and empty strings: ....... Git dates: ........... ISO 8601 moment.js: ................................. ISO 8601 Pelago: ...................................... ISO 8601 Pelago non-matching: ....................... ISO week dates: ... DONE =========================================================================== Warning message: package 'testthat' was built under R version 3.2.5 http://kbroman.org/pkg_primer/pages/docs.html

Testthat test cases in parsedate Testthat.r: library(testthat) library(parsedate) test_check("parsedate") http://kbroman.org/pkg_primer/pages/docs.html

Testthat test cases in parsedate http://kbroman.org/pkg_primer/pages/docs.html

Testthat documentation Context – name under which to group tests test_that(name,code) – create a test Expect_equal – checks if 2 values are the same See documentation for other types of equality-expectations Also see document for “mock” usage for complicated out-of-package function substitution http://kbroman.org/pkg_primer/pages/docs.html

Testthat parsedate example context("ISO week dates") test_that("Exotic ISO week dates are OK", { tests <- read.table(stringsAsFactors = FALSE, header = FALSE, strip.white = TRUE, row.names = NULL, sep = "|", textConnection(" 2009-W01-1 | 2008-12-29T00:00:00+00:00 2009-W53-7 | 2010-01-03T00:00:00+00:00 2013-W06-5 | 2013-02-08T00:00:00+00:00" )) apply(tests, 1, function(x) { d <- format_iso_8601(parse_iso_8601(x[1])) expect_equal(d, unname(x[2])) }) Expected output http://kbroman.org/pkg_primer/pages/docs.html Input to parse function

Testthat parsedate - boundary checks (corner cases) also done test_that("Non-sensical input is removed", { date <- "?=)(!$§#$%" expected <- as.POSIXct(NA) actual <- parse_date(date) expect_equal(expected, actual) }) http://kbroman.org/pkg_primer/pages/docs.html

Testthat added as a test context("BJF examples") library(stringr) test_that("Example 1 BJF", { tests <- read.table(stringsAsFactors = FALSE, header = FALSE, strip.white = TRUE, row.names = NULL, sep = "|", textConnection(" 2013-02-08T09:30:26.123 | 2013-02-08T10:30:26+00:00 2013-02-08T09:30:26.123 | 2013-02-08T09:30:26+00:00 " )) apply(tests, 1, function(x) { d <- format_iso_8601(parse_iso_8601(x[1])) expect_equal(d, unname(x[2]), info = x[1]) }) http://kbroman.org/pkg_primer/pages/docs.html

Testthat added as a test test_that("Example for BJF", { tests <- read.table(stringsAsFactors = FALSE, header = FALSE, strip.white = TRUE, row.names = NULL, sep = "|", textConnection(" The sky is blue | red The sky is blue | blue " )) apply(tests, 1, function(x) { d <- (word(x[1],-1)) expect_equal(d, unname(x[2]), info = x[1]) }) http://kbroman.org/pkg_primer/pages/docs.html

Testthat added as a test - output ==> devtools::test() Loading parsedate Loading required package: testthat Testing parsedate BJF examples.js: 1.2. Dates and empty strings: ....... Git dates: ........... ISO 8601 moment.js: ................................. ISO 8601 Pelago: ...................................... ISO 8601 Pelago non-matching: ....................... ISO week dates: ... Failed ------------------------------------------------------------------------- 1. Failure: Examples for BJF.js (@test-bjfexample.R#16) ------------------------ `d` not equal to unname(x[2]). 1/1 mismatches x[1]: "2013-02-08T09:30:26+00:00" y[1]: "2013-02-08T10:30:26+00:00" 2013-02-08T09:30:26.123 2. Failure: Examples for BJF.js (@test-bjfexample.R#32) ------------------------ x[1]: "blue" y[1]: "red" The sky is blue http://kbroman.org/pkg_primer/pages/docs.html

Testthat - describe describe(function,code) – description of function and its test (alternative function in test_that package) http://kbroman.org/pkg_primer/pages/docs.html

Testthat – describe added as test describe("parse_iso_8601()", { it ("can convert fractional hours and time zone offset",{ tests <- read.table(stringsAsFactors = FALSE, header = FALSE, strip.white = TRUE, row.names = NULL, sep = "|", textConnection(" 2010-02-18T16:23.33+0600 | 2010-02-18T10:23:19+00:00 " )) apply(tests, 1, function(x) { d <- format_iso_8601(parse_iso_8601(x[1])) expect_equal(d, unname(x[2]), info = x[1]) }) http://kbroman.org/pkg_primer/pages/docs.html

Q&A Alphabetically within that “testthat” directory How does Testthat determine which files to run? In Rstudio, under project -> build -> test package runs: devtools::test() This command, by defaults, looks for a subdirectory “tests” And within that a subdirectory “testthat” Files found that are within the “testthat” directory and start with “test” are run. What are the order of the files run? Alphabetically within that “testthat” directory What naming conventions must be followed? Test files must start with “test” Convention (not mandatory) is that they start with “test-” They must end with a “r” or “R” http://kbroman.org/pkg_primer/pages/docs.html