Skip to content

Commit

Permalink
🐛 - fix path error on windows; deprecate path functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocoretta committed Apr 19, 2021
1 parent 6f6ff33 commit e2dc448
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 82 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BugReports: https://github.com/stefanocoretta/speakr/issues
Encoding: UTF-8
RoxygenNote: 7.1.1
Imports: tidyverse,
lifecycle,
readr,
stringr
Suggests: knitr,
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(get_praat_path)
export(praat_open)
export(praat_plot)
export(praat_run)
export(set_praat_path)
export(start_praat)
export(use_praat_plot_script)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

* Now the path to Praat is set on load and calls to the package namespace with `::` will work (closes #5).

## Deprecated

* `set_praat_path()` and `get_praat_path()` have been deprecated. Now the package relies on `options("speakr.praat.path")`.



# speakr 3.0.0

Expand Down
2 changes: 0 additions & 2 deletions R/env.R

This file was deleted.

37 changes: 22 additions & 15 deletions R/paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,44 @@ praat_path <- function() {
} else if (sysname == "Linux") {
return("/usr/bin/praat")
} else if (sysname == "Windows") {
return(normalizePath("C:/Program Files/Praat.exe"))
return(normalizePath("C:/Program Files/Praat.exe", mustWork = FALSE))
}
}

#' Set path to 'Praat'.
#'
#' It assigns the default path to 'Praat' or the user assigned path (when
#' \code{default.path = FALSE}, which is the default).
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' @param path The path to the 'Praat' executable.
#' @param default.path If \code{TRUE}, the path is set to what \code{praatPath}
#' returns.
#' Now speakr uses options() to set the path to 'Praat'.
#'
#' @return Nothing. It is used for its side effects.
#'
#' @export
#' @keywords internal
set_praat_path <- function(path, default.path = FALSE) {
lifecycle::deprecate_warn(
"3.1.0",
"set_praat_path()",
details = "Please use `options('speakr.praat.path')` instead."
)
if (default.path == FALSE) {
pkg.env$praat.path <- path
options(speakr.praat.path = path)
} else {
pkg.env$praat.path <- praat_path()
options(speakr.praat.path = praat_path())
}
}

#' Print path to 'Praat'.
#'
#' It prints the path to 'Praat' on the console for inspection.
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' @return A character vector with the 'Praat' path.
#' Now speakr uses options() to set the path to 'Praat'.
#'
#' @export
#' @keywords internal
get_praat_path <- function() {
return(pkg.env$praat.path)
lifecycle::deprecate_warn(
"3.1.0",
"set_praat_path()",
details = "Please use `options(speakr.praat.path = './praat')` instead."
)
return(getOption("speakr.praat.path"))
}
8 changes: 4 additions & 4 deletions R/praat.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @export
start_praat <- function() {
system2(pkg.env$praat.path, wait = FALSE)
system2(getOption("speakr.praat.path"), wait = FALSE)
}

#' Open files with 'Praat'.
Expand Down Expand Up @@ -40,7 +40,7 @@ start_praat <- function() {
#'
#' @export
praat_open <- function(...) {
system2(pkg.env$praat.path, c("--open", list(...)), wait = FALSE)
system2(getOption("speakr.praat.path"), c("--open", list(...)), wait = FALSE)
}

#' Run a 'Praat' script.
Expand Down Expand Up @@ -73,9 +73,9 @@ praat_open <- function(...) {
#' @export
praat_run <- function(script, ..., capture = FALSE) {
if (capture == FALSE) {
system2(pkg.env$praat.path, c("--run", c(script, list(...))))
system2(getOption("speakr.praat.path"), c("--run", c(script, list(...))))
} else {
output <- system2(pkg.env$praat.path, c("--run", c(script, list(...))),
output <- system2(getOption("speakr.praat.path"), c("--run", c(script, list(...))),
stdout = capture
)
return(paste(output, collapse = "\n"))
Expand Down
4 changes: 1 addition & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
toset <- !(names(op.speakr) %in% names(op))
if (any(toset)) options(op.speakr[toset])

set_praat_path(getOption("speakr.praat.path"))

invisible()
}

.onAttach <- function(libname, pkgname) {
praat_path <- get_praat_path()
praat_path <- getOption("speakr.praat.path")

if (file.exists(praat_path)) {
packageStartupMessage("Praat found at ", praat_path)
Expand Down
43 changes: 2 additions & 41 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,11 @@
## Test environments
* local R installation, R 4.0.5
* ubuntu 16.04 (on travis-ci), R 4.0.5

* local macOS 11.2.3 (r-4.0.5)
* win-builder (devel)
* R-hub windows-x86_64-devel (r-devel)
* R-hub ubuntu-gcc-release (r-release)
* R-hub fedora-clang-devel (r-devel)

## 1 NOTE

The package relies on external software (Praat) to function. On load, the path to Praat is set as an option, depending on the OS. No attempt is made to run Praat on load, so the note on Windows about not finding the file "C:/Program Files/Praat.exe" is possibly spurious.

## R CMD check results

── speakr 3.1.0: NOTE

Build ID: speakr_3.1.0.tar.gz-e57da25b977a441a960d4352ba057a8d
Platform: Windows Server 2008 R2 SP1, R-devel, 32/64 bit
Submitted: 1h 1m 46.3s ago
Build time: 4m 44.5s

> checking whether the namespace can be loaded with stated dependencies ... NOTE
Warning in normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Program Files/Praat.exe": The system cannot find the file specified

A namespace must be able to be loaded with just the base namespace
loaded: otherwise if the namespace gets loaded by a saved object, the
session will be unable to start.

Probably some imports need to be declared in the NAMESPACE file.

0 errors ✓ | 0 warnings ✓ | 1 note x

── speakr 3.1.0: OK

Build ID: speakr_3.1.0.tar.gz-824e56eeb3fc4219982cbb8a633fe929
Platform: Ubuntu Linux 20.04.1 LTS, R-release, GCC
Submitted: 1h 1m 46.3s ago
Build time: 12m 18.5s

0 errors ✓ | 0 warnings ✓ | 0 notes ✓

── speakr 3.1.0: OK

Build ID: speakr_3.1.0.tar.gz-460ef8b0dcab4325b2c47dfb7290beb5
Platform: Fedora Linux, R-devel, clang, gfortran
Submitted: 1h 1m 46.3s ago
Build time: 12m 35.7s

0 errors ✓ | 0 warnings ✓ | 0 notes ✓
8 changes: 4 additions & 4 deletions man/get_praat_path.Rd

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

15 changes: 4 additions & 11 deletions man/set_praat_path.Rd

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

0 comments on commit e2dc448

Please sign in to comment.