Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace questionable characters in filenames #6

Closed
hadley opened this issue Jul 13, 2011 · 1 comment
Closed

Replace questionable characters in filenames #6

hadley opened this issue Jul 13, 2011 · 1 comment
Labels
feature a feature request or enhancement

Comments

@hadley
Copy link
Member

hadley commented Jul 13, 2011

library(gsubfn)
library(functional)

##' Substitutions of questionable characters with a hacker-joke to
##' boot.
substitutions=c(
  `!`='bang',
  `"`='quote',
  `#`='hash',
  `$`='cash',                           # sigil
  `%`='grapes',
  `&`='and',
  `'`='single-quote',
  `(`='open-paren',
  `)`='close-paren',
  `*`='star',
  `+`='plus',
  `,`='comma',
  `-`='dash',
  `.`='dot',
  `/`='slash',
  `:`='colon',
  `;`='semi-colon',
  `<`='less-than',
  `=`='equals',
  `>`='greater-than',
  `?`='p',
  `@`='asperand',
  `[`='open-brace',
  `\\`='backslash',
  `]`='close-brace',
  `^`='hat',
  `_`='sub',
  '`'='backtick',                       # let's add another ` to
                                        # rectify syntax highlighting
                                        # in emacs; thanks.
  `{`='open-curly',
  `|`='pipe',
  `}`='close',
  `~`='not'
  )

##' \code{NULL} if empty-string.
##' @param string string to check
##' @return \code{NULL} or identity
nil_if_lambda <- function(string)
  if (nchar(string)) string else NULL

##' Translate file-system-questionable characters (i.e. punctuation
##' within ASCII).
##' @param filename the filename to translate
##' @return the translated filename
translate_questionable_characters <- function(filename)
  do.call(Curry(paste, collapse="-"),
          strapply(filename,
                   pattern='([[:punct:]]|)([^[:punct:]]*|)',
                   function(punctuation, letters)
                   c(substitutions[nil_if_lambda(punctuation)],
                     nil_if_lambda(letters))))

translate_questionable_characters('%||%')
@klutometis
Copy link
Collaborator

This is a bug Michael Lawrence brought to my attention a few months back regarding 1.0; would it be reasonable to port it to 2.0, or are we content to ignore documented functions with non-alphabetic characters?

@hadley hadley closed this as completed in 9de69bd Oct 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants