####################################################################################################
#
# Functions for working with operating and file systems
#
# @author ConradStack <conrad.stack@gmail.com>
#
#' Return simplified operating system name
#'
#' @return simplified os name
#' @export
get_os <- function(){
sysinf <- Sys.info()
if (!is.null(sysinf)){
os <- sysinf['sysname']
if (os == 'Darwin')
os <- "osx"
} else { ## mystery machine
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
if (grepl("linux-gnu", R.version$os))
os <- "linux"
}
tolower(os)
}
#' Working with filenames
#'
#' Return the part of the file before the final period (i.e., the file extension). The file does not have to exist
#'
#' @param filename a string representing a filename
#'
#' @return filename prefix or extension
#' @export
file_prefix <- function(filename)
{
ftmp = strsplit(filename,"\\.")[[1]]
if(length(ftmp) == 1)
return (ftmp)
fpre = paste(head(ftmp,-1),collapse='.')
fpre
}
#' @describeIn file_prefix Return the part of the file before the final period (i.e., the file extension). The file does not have to exist
#' @export
file_ext <- function(filename)
{
ftmp = strsplit(filename,"\\.")[[1]]
if(length(ftmp) == 1)
return ("")
fext = tail(ftmp,1)
fext
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.