Skip to content

Commit

Permalink
v2.1 - Added support for Linux; fixed Mac/Linux bug
Browse files Browse the repository at this point in the history
  • Loading branch information
usagi5886 committed Nov 6, 2014
1 parent dbe3415 commit ba8f810
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 35 deletions.
4 changes: 2 additions & 2 deletions PraatR/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: PraatR
Type: Package
Title: An architecture for controlling the phonetics software 'Praat'
Version: 2.0
Date: 2014-10-24
Version: 2.1
Date: 2014-11-05
Author: Aaron Albin
Maintainer: Aaron Albin <[email protected]>
Description: The function 'praat()' sends a shell command to the operating
Expand Down
4 changes: 4 additions & 0 deletions PraatR/NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
NEWS in package 'PraatR'

2.1 11-05-2014
o Added support for Linux
o Fixed bug where commands with parentheses would issue an error (Mac/Linux only)

2.0 10-24-2014
o Released as an R package to allow simpler loading simply by calling 'library("PraatR")'
o Created documentation for the package, e.g. the help file displayed when typing '?praat'
Expand Down
70 changes: 49 additions & 21 deletions PraatR/R/praat.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,24 +334,41 @@ ArgumentString = paste( UnderscoreSwapped, collapse=" ")
# Adjust based on user operating system (OS) #
##############################################

UserOS = .Platform$OS.type # "windows" for a Windows 8, "unix" for Linux or Mac.
# Linux vs. Mac can be distinguished by querying Sys.info()["sysname"], which returns "Windows", "Linux", or "Darwin" (=Mac).
# (When Linux support is added, perhaps just use this instead?)

# In Windows, R.home("library") is something like "C:/PROGRA~1/R/R-30~1.3/library", which lacks a space, so this should always work fine.
if( ! UserOS %in% c("windows","unix")){stop("Operating system not supported. .Platform$OS.type must be either 'windows' or 'unix'.")}
if(UserOS == "windows"){
PraatPath = paste(R.home("library"),"PraatR","praatcon.exe",sep="/");
if(!file.exists(PraatPath)){ stop(paste("Praat not found. Make sure praatcon.exe has been placed in this folder:\n ",find.package("PraatR"),sep="")) } # Use find.package("PraatR") rather than 'PraatPath' in order to make the result more human-readable
} # End 'if Windows'
if(UserOS == "unix" ){
PraatPath = "/Applications/Praat.app/Contents/MacOS/Praat"
# Presumably it will always be in this one fixed/stable location, but check just in case:
if(!file.exists("/Applications/Praat.app")){ stop("Praat not found. Make sure Praat is installed in this location:\n /Applications/Praat.app") }
}
OSType = .Platform$OS.type # "windows" for Windows, "unix" for Linux or Mac
SystemName = Sys.info()["sysname"] # "Windows", "Linux", or "Darwin" (=Mac)

if( OSType=="windows" & SystemName=="Windows" ){
UserOS = "Windows" # For later down below in the code
PraatPath = paste(R.home("library"),"PraatR","praatcon.exe",sep="/")
# In Windows, R.home("library") is something like "C:/PROGRA~1/R/R-30~1.3/library", which lacks a space, so this should always work fine.
if(!file.exists(PraatPath)){ stop(paste("Praat not found. Make sure praatcon.exe has been placed in this folder:\n ",find.package("PraatR"),sep="")) } # Use find.package("PraatR") rather than 'PraatPath' in order to make the result more human-readable
}else{
if( OSType=="unix" & SystemName=="Darwin" ){
UserOS = "Mac" # For later down below in the code
PraatPath = "/Applications/Praat.app/Contents/MacOS/Praat"
# Presumably it will always be in this one fixed/stable location, but check just in case:
if(!file.exists("/Applications/Praat.app")){ stop("Praat not found. Make sure Praat is installed in this location:\n /Applications/Praat.app") }
}else{
if( OSType=="unix" & SystemName=="Linux" ){
UserOS = "Linux" # For later down below in the code
PathSeparator = .Platform$path.sep # For Linux, should always be ":" (colon)
SystemPathList = Sys.getenv("PATH") # Something like "/home/myusername/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
PossiblePraatLocations = paste(strsplit(SystemPathList,split=PathSeparator)[[1]],"praat",sep="/")
PraatFound = sapply(PossiblePraatLocations,FUN=file.exists)
if(sum(PraatFound)==0){stop("Praat executable not found. (Make sure it is in your PATH.)")}
#FoundIndex = which(PraatFound)[1] # If it's in more than one of the directories, use the first one in that order
#PraatPath = PossiblePraatLocations[FoundIndex] # Usually "/usr/bin/praat" or "/usr/local/bin/praat", depending on how the user has installed Praat
PraatPath = "praat"
}else{
stop("Operating system not supported. For support, feel free to e-mail the creator of PraatR.")
} # End 'if/else Linux'
} # End 'if/else Mac'
} # End 'if/else Windows'

##################################
# Determine path to Praat script #
##################################

# Do a similar string of checks to how the SupportedCommands path was found
# (Most of this code is copied from there.)
LibraryDirectories = unique( c( R.home("library"), .libPaths() ) )
nDirectories = length(LibraryDirectories)

Expand Down Expand Up @@ -399,8 +416,14 @@ CommandString = paste( PraatPath,
intern = FALSE # Do *not* capture anything from the Info Window of Praat (for bringing back into R)

# Now, finally issue the instruction to the OS
if(UserOS == "windows"){ shell(cmd=CommandString, intern=intern) } # For Windows
if(UserOS == "unix"){ system(command=CommandString, intern=intern) } # For Unix/Mac
if( UserOS == "Windows" ){ shell(cmd=CommandString, intern=intern) }
if( UserOS == "Mac" | UserOS == "Linux" ){
# Escape any parentheses in the entire command string.
CommandStringA = gsub(CommandString,pattern="(",replacement="\\(",fixed=TRUE)
CommandStringB = gsub(CommandStringA,pattern=")",replacement="\\)",fixed=TRUE)
system(command=CommandStringB, intern=intern)
} # End 'if Mac'

# Eventually, somehow detailedly check the response status from this function call and issue custom messages accordingly to help the user troubleshoot if there are any problems?

} # End 'if this is a query command'
Expand All @@ -422,8 +445,13 @@ CommandString = paste( PraatPath,
intern = TRUE # This indicates that the ultimate contents of the Info Window in Praat should be captured and brought back into R

# Now, finally issue the instruction to the OS, and return the result
if(UserOS == "windows"){ return(shell(cmd=CommandString, intern=intern)) } # For Windows
if(UserOS == "unix"){ return(system(command=CommandString, intern=intern)) } # For Unix/Mac
if( UserOS == "Windows" ){ return(shell(cmd=CommandString, intern=intern)) }
if( UserOS == "Mac" | UserOS == "Linux" ){
# Escape any parentheses in the entire command string.
CommandStringA = gsub(CommandString,pattern="(",replacement="\\(",fixed=TRUE)
CommandStringB = gsub(CommandStringA,pattern=")",replacement="\\)",fixed=TRUE)
return(system(command=CommandStringB, intern=intern))
} # End 'if Mac'

} # End 'if this is a query command'

Expand Down
9 changes: 4 additions & 5 deletions PraatR/man/PraatR-package.Rd → PraatR/man/PraatR.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\name{PraatR-package}
\name{PraatR}

\alias{PraatR}

Expand All @@ -13,9 +13,9 @@ PraatR is an architecture for controlling the phonetics software Praat (\url{htt
\tabular{ll}{
Package: \tab PraatR\cr
Type: \tab Package\cr
Version: \tab 2.0\cr
Date: \tab 2014-10-24\cr
License: \tab GNU General Public License\cr
Version: \tab 2.1\cr
Date: \tab 2014-11-05\cr
License: \tab GNU General Public License (Version 3 or later)\cr
}
For information on how to use \code{\link{praat}()}, see \url{ http://www.aaronalbin.com/praatr/ }. For information about the various commands that can be executed, see \url{ http://www.aaronalbin.com/praatr/commands.html }.
}
Expand All @@ -33,4 +33,3 @@ Albin, A. (2014). PraatR: An architecture for controlling the phonetics software
\seealso{
\code{\link{praat}}
}
9 changes: 2 additions & 7 deletions PraatR/man/praat.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,11 @@ Aaron Albin (\url{http://www.aaronalbin.com/})
}
\note{
PraatR is currently only supported on Windows and Mac.
\itemize{
\item{In order for PraatR to work on Windows, you must have downloaded a separate file called \code{praatcon.exe} and placed it your PraatR library folder.}
\item{In order for PraatR to work on Mac, Praat needs to be installed on your computer in the following location: \code{/Applications/Praat.app}.}
}
For details, see the 'Installation' section of the PraatR homepage.
Further information - including installation instructions, a basic tutorial, and the list of supported commands - is available at the PraatR homepage: \url{http://www.aaronalbin.com/praatr/}.
}
\seealso{
Further information - including installation instructions, a basic tutorial, and the list of supported commands - is available at the PraatR homepage: \url{http://www.aaronalbin.com/praatr/}.
\code{\link{PraatR}}
}
\examples{
Expand Down

0 comments on commit ba8f810

Please sign in to comment.