Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ribiosUtils
Type: Package
Title: Utilities from and Interface to the 'Bioinfo-C' ('BIOS') Library
Version: 1.7.8
Date: 2026-01-22
Version: 1.7.9
Date: 2026-03-17
Authors@R:
c(person(given = "Jitao David",
family = "Zhang",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export(compTwoVecs)
export(corByRownames)
export(countTokens)
export(createDir)
export(createRmdTemplate)
export(cumJaccardDistance)
export(cumJaccardIndex)
export(cumOverlapCoefficient)
Expand Down
48 changes: 48 additions & 0 deletions R/createRmdTemplate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#' Copy the skeleton RMarkdown file to a specified location
#'
#' This function copies the skeleton RMarkdown template shipped with
#' \code{ribiosUtils} to the current working directory (or any specified path)
#' under a user-given file name. When no file name is provided, a default name
#' based on the current date is used.
#'
#' @param filename Character string, the name (or path) of the destination
#' file. If \code{NULL} (default), the file is named
#' \code{Report_[YYYY-DD-MM]-report.Rmd}, where the date components reflect
#' the current date.
#' @param overwrite Logical, whether to overwrite an existing file. Default is
#' \code{FALSE}.
#' @return The path of the copied file (invisible).
#' @author Jitao David Zhang <jitao_david.zhang@@roche.com>
#' @examples
#' \dontrun{
#' ## copy with default file name
#' createRmdTemplate()
#'
#' ## copy with a custom file name
#' createRmdTemplate("my_analysis.Rmd")
#' }
#'
#' ## copy to a temporary directory
#' dest <- createRmdTemplate(file.path(tempdir(), "test_report.Rmd"))
#' file.exists(dest)
#' unlink(dest)
#'
#' @export
createRmdTemplate <- function(filename = NULL, overwrite = FALSE) {
if (is.null(filename)) {
filename <- format(Sys.time(), "Report_%Y-%d-%m-report.Rmd")
}
skeleton <- system.file("rmarkdown", "templates",
"ribios-rmarkdown-template", "skeleton", "skeleton.Rmd",
package = "ribiosUtils")
if (skeleton == "") {
stop("Skeleton file not found in ribiosUtils installation.")
}
if (file.exists(filename) && !overwrite) {
stop("File '", filename, "' already exists. ",
"Use overwrite=TRUE to overwrite.")
}
file.copy(skeleton, filename, overwrite = overwrite)
message("Skeleton file copied to '", filename, "'")
return(invisible(filename))
}
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ distributed under the GPL-3 license.

## Installation

### Install the devel version from GitHub
### Install the stable version on CRAN

Run following commands in the R console.

```{R}
library(devtools)
devtools::install_github("bedapub/ribiosUtils")
```r
install.packages("ribiosUtils")
```

### Install the stable version on CRAN

*The CRAN version is temporarily not available due to pending changes*.
### Install the devel version from GitHub

```r
install.packages("ribiosUtils")
```{R}
library(devtools)
devtools::install_github("bedapub/ribiosUtils")
```

## History
Expand Down
44 changes: 44 additions & 0 deletions man/createRmdTemplate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions tests/testthat/test_createRmdTemplate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library(testthat)
library(ribiosUtils)

context("createRmdTemplate")

test_that("createRmdTemplate copies the skeleton file with a custom name", {
dest <- file.path(tempdir(), "test_skeleton.Rmd")
on.exit(unlink(dest))
result <- createRmdTemplate(dest)
expect_true(file.exists(dest))
expect_equal(result, dest)
})

test_that("createRmdTemplate uses default filename when none given", {
old_wd <- setwd(tempdir())
on.exit(setwd(old_wd))
result <- createRmdTemplate()
on.exit(unlink(result), add = TRUE)
expect_true(file.exists(result))
expect_true(grepl("^Report_.*-report\\.Rmd$", basename(result)))
})

test_that("createRmdTemplate refuses to overwrite by default", {
dest <- file.path(tempdir(), "test_no_overwrite.Rmd")
on.exit(unlink(dest))
createRmdTemplate(dest)
expect_error(createRmdTemplate(dest), "already exists")
})

test_that("createRmdTemplate overwrites when overwrite=TRUE", {
dest <- file.path(tempdir(), "test_overwrite.Rmd")
on.exit(unlink(dest))
createRmdTemplate(dest)
expect_message(createRmdTemplate(dest, overwrite = TRUE), "Skeleton file copied")
expect_true(file.exists(dest))
})
Loading