-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 61-hide-inputs
- Loading branch information
Showing
6 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' Create a new block | ||
#' | ||
#' Create a new block | ||
#' | ||
#' @param name Block name. | ||
#' @param type Type of block to create. | ||
#' @param file Output file. | ||
#' If `NULL` then it constructs `R/<name>-block.R`. | ||
#' | ||
#' @export | ||
create_block <- function( | ||
name, | ||
type = c("transform", "plot"), | ||
file = NULL) { | ||
if (missing(name)) { | ||
stop("Missing `name`") | ||
} | ||
|
||
type <- match.arg(type) |> | ||
(\(.) sprintf("%s_block", .))() | ||
|
||
if (is.null(file)) { | ||
file <- file.path( | ||
"R", | ||
sprintf("%s-block.R", name) | ||
) | ||
} | ||
|
||
file_name <- sprintf("%s.R", type) | ||
infile <- system.file( | ||
file.path("templates", file_name), | ||
package = "blockr" | ||
) | ||
|
||
content <- readLines(infile) |> | ||
gsub("NAME", name, x = _) | ||
|
||
writeLines(content, con = file) | ||
|
||
cat("File", file, "created!\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' NAME | ||
#' | ||
#' A new plot block. | ||
#' | ||
#' @export | ||
NAME_block <- function(data, ...) { | ||
all_cols <- function(data) colnames(data) | ||
|
||
fields <- list( | ||
x_var = new_select_field("VISIT", all_cols), | ||
y_var = new_select_field("MEAN", all_cols) | ||
) | ||
|
||
new_block( | ||
fields = fields, | ||
expr = quote({ | ||
ggplot( | ||
data, | ||
mapping = aes_string( | ||
x = .(x_var), | ||
y = .(y_var) | ||
) | ||
) + | ||
geom_point() + | ||
geom_line() | ||
}), | ||
..., | ||
class = c("NAME_block", "plot_block") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#' NAME | ||
#' | ||
#' A new transform block. | ||
#' | ||
#' @export | ||
NAME_block <- function(data, ...) { | ||
fields <- list( | ||
n_rows = new_numeric_field(10, 10, nrow(data)) | ||
) | ||
|
||
new_block( | ||
fields = fields, | ||
expr = quote({ | ||
head(data, .(n_rows)) | ||
}), | ||
..., | ||
class = c("NAME_block", "transform_block") | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.