Skip to content

Commit

Permalink
Separate .onLoad() and .onAttach(). Remove captue.output().
Browse files Browse the repository at this point in the history
  • Loading branch information
leonawicz committed Sep 21, 2023
1 parent 1cc34d1 commit 2fcd3f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ lilypond_version <- function(){
#' @rdname lilypond_root
#' @export
tabr_lilypond_api <- function(){
message(.tabr_lilypond_api())
}

.tabr_lilypond_api <- function(){
os <- Sys.info()[["sysname"]]
if(grepl("Darwin", os, ignore.case = TRUE)) os <- "MacOS"
x <- switch(
Expand All @@ -39,11 +43,10 @@ tabr_lilypond_api <- function(){
)
x <- paste("LilyPond", x)

msg <- paste0(
paste0(
"The tabr ", getNamespaceVersion("tabr"),
" LilyPond API was built and tested against ", x, " on ", os, "."
)
message(msg)
}

.tabr_api_lp_versions <- list(
Expand Down
9 changes: 6 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.onAttach <- function(lib, pkg){
.onLoad <- function(lib, pkg){
x <- c("lilypond", "midi2ly", "python")
lp_path <- as.character(Sys.which(x[1]))
ml_path <- as.character(Sys.which(x[2]))
Expand All @@ -15,10 +15,13 @@
}

tabr_options(lilypond = lp_path, midi2ly = ml_path, python = py_path)
}

msg <- paste0(utils::capture.output(tabr_lilypond_api(), type = "message"), "\n")

.onAttach <- function(lib, pkg){
lp_path <- tabr_options()$lilypond
msg <- paste0(.tabr_lilypond_api(), "\n")
no_lp <- gsub("\\.$", " (only required for transcription).", .lp_not_found)

if(lp_path == ""){
msg <- paste0(msg, no_lp)
} else {
Expand Down

0 comments on commit 2fcd3f6

Please sign in to comment.