datacamp / testwhat.ext Goto Github PK
View Code? Open in Web Editor NEWextensions (high-level SCTs) for testwhat
Home Page: https://datacamp.github.io/testwhat.ext/
License: GNU Affero General Public License v3.0
extensions (high-level SCTs) for testwhat
Home Page: https://datacamp.github.io/testwhat.ext/
License: GNU Affero General Public License v3.0
After a lot of digging, I figured out that travis CI choked on this test, so I decided to disable it. Probably something tricky going on with the lib paths. I'm not going to invest time in this right now, but anybody else is welcome to ! cc @richierocks ;)
roxygen2:::parse_blocks()
imports these in a weird format that makes tests hard to write.
@import
ought to become a character vector of package names.
@importFrom
ought to become a list of character vectors. The names of the elements ought to be packages, and the character vectors ought to be names of objects imported from those packages.
From Devel R Pkgs Ch2 Ex9:
#' @examples
#' data_summary(iris)
#' data_summary(airquality, na.rm = FALSE)
data_summary <- function(x, na.rm = TRUE){
num_data <- select_if(x, .predicate = is.numeric)
map_df(num_data, .f = numeric_summary, na.rm = na.rm, .id = "ID")
}
The examples don't run because dplyr and purrr aren't loaded.
I think the easiest fix is to run the pre-exercise code in the student environment/solution environment before running the example code.
So in the PEC, you would write
library(dplyr)
library(purrr)
This affects check_roxy_examples_run()
and check_roxy_examples_result_equals()
.
You can write code to draw base plots in several ways. For example, the following are all equivalent.
plot(cars$speed, cars$dist)
plot(dist ~ speed, cars)
with(cars, plot(speed, dist))
library(magrittr)
cars %$% plot(speed, dist)
Writing SCTs to check for all syntaxes is tricky. You have to do something like this:
test_or({
ex() %>% check_function('plot') %>% {
check_arg(., 'x') %>% check_equal()
check_arg(., 'y') %>% check_equal()
}
}, {
ex() %>% override_solution('plot(dist ~ speed, cars))') %>% check_function('plot') %>% {
check_arg(., 'formula') %>% check_equal()
check_arg(., 'data') %>% check_equal()
}
}, {
ex() %>% override_solution('with(cars, plot(speed, dist))') %>% check_function('with') %>% {
check_arg(., 'data') %>% check_equal()
check_arg(., 'expr') %>% check_function('plot') %>% {
check_arg(., 'x') %>% check_equal(eval = FALSE)
check_arg(., 'y') %>% check_equal(eval = FALSE)
}
}
}, {
ex() %>% override_solution('cars %$% plot(speed, dist)') %>% {
check_code(., 'cars %$%', fixed = TRUE)
check_function(., 'plot') %>% {
check_arg(., 'x') %>% check_equal(eval = FALSE)
check_arg(., 'y') %>% check_equal(eval = FALSE)
}
}
})
Ideally, there would be a test_base_plot()
function that handled all the specific cases.
One complication is that formula syntax is not supported for all base plot types. For example, hist()
doesn't allow this. So you'd need a completely separate test_base_hist()
.
It might be easier from a technical point of view if the plot was first converted to a grid plot, in order to have an object to test. You can do this using grid.echo()
and grid.grab()
from the gridGraphics
package.
See https://journal.r-project.org/archive/2015-1/murrell.pdf
FYI For base plotting, the Data Visualization in R course has longer, messy SCTs for the different cases in Ch1 and Ch2 (I didn’t get round to doing them for the later chapters yet) https://github.com/datacamp/courses-data-vis-in-r
Looks like testwhat.ext
no longer exports check_roxy_imports_package()
and check_roxy_imports_object_from_package()
. @richierocks wrote the following SCT a while ago, but it no longer works.
#' @import dplyr
#' @import purrr
#' @importFrom tidyr gather
library(testwhat.ext)
ex() %>%
parse_roxy() %>% {
check_roxy_imports_package(., "dplyr")
check_roxy_imports_package(., "purrr")
check_roxy_imports_object_from_package(., "tidyr", "gather")
}
Was this accidental or is this replaced by some other functions? The plan is to launch the course by EOD, Friday (Aug 24). So any help is much appreciated!
cc @filipsch
@richierocks a new version of roxygen2
came out, version 6.1.0, and parse_blocks
is no longer a hidden function in the package. You use this function in the R/parse.R
file to find the roxygen blocks.
As these functions are nowhere used for the moment, I temporarily commented out the tests (in this branch). Feel free to do a PR that makes things work again. I can also do it at some point.
I personally don't think it makes sense to sink time in this until the functions are actually needed.
In the Bayesian Modeling with RJAGS course, JAGS models have to be specified as a string.
This means that many students are complaining about overly strict SCTs that don't allow for variation in spacing and simple formatting differences.
I had a play around in the internals of rjags
, but there's no obvious way of extracting a normalized or compiled model.
However, since JAGS model code is very close to R code, formatR::tidy_source()
can be used to standardize the spacing.
tidy_code <- function(x) {
tidied <- formatR::tidy_source(
text = x,
comment = FALSE,
blank = FALSE,
arrow = TRUE,
output = FALSE
)$text.tidy
unlist(strsplit(tidied, "\n"))
}
Example usage is
model_text <- "model
{
# Likelihood model for Y[i]
for (i in 1: length( Y) )
{
Y[i] ~ dnorm( m, s ^(-2))
}
# Prior models for m and s
m ~ dnorm(50, 25 ^( -2) )
s ~ dunif (0, 200)
}"
tidy_code(model_text)
## [1] "model" "{"
## [3] " for (i in 1:length(Y)) {" " Y[i] ~ dnorm(m, s^(-2))"
## [5] " }" " m ~ dnorm(50, 25^(-2))"
## [7] " s ~ dunif(0, 200)" "}"
My current plan is to combine this with
tidy_ex_code <- function(state) {
childState <- ChildState$new(state)
childState$set(
student_code = tidy_code(childState$get("student_code")),
solution_code = tidy_code(childState$get("solution_code"))
)
return(invisible(childState))
}
in order to be able to write SCTs like
ex() %>% tidy_ex_code() %>% {
# check something
}
Does this sound like a sensible approach?
If the object being parsed has the value "_PACKAGE"
, then roxygen2:::parse_blocks()
goes hunting for the DESCRIPTION file, which in this case doesn't exist.
Find some way to turn this behavior off!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.