[Roxygen-commits] r252 - in pkg: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 11 04:27:48 CET 2011


Author: pcd
Date: 2011-03-11 04:27:44 +0100 (Fri, 11 Mar 2011)
New Revision: 252

Modified:
   pkg/DESCRIPTION
   pkg/R/Rd.R
   pkg/TODO
Log:
translate filenames with questionable characters

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2011-01-28 15:09:44 UTC (rev 251)
+++ pkg/DESCRIPTION	2011-03-11 03:27:44 UTC (rev 252)
@@ -9,7 +9,7 @@
     from Hadley Wickham <hadley at rice.edu>
 Maintainer: Peter Danenberg <pcd at roxygen.org>
 URL: http://roxygen.org
-Depends: digest
+Depends: digest, gsubfn
 Suggests: Rgraphviz (>= 1.19.2), tools (>= 2.9.1), testthat
 Collate: 'functional.R' 'list.R' 'roxygen.R' 'string.R' 'memoize.R' 'parse.R'
     'parseS4.R' 'roclet.R' 'callgraph.R' 'description.R' 'collate.R'

Modified: pkg/R/Rd.R
===================================================================
--- pkg/R/Rd.R	2011-01-28 15:09:44 UTC (rev 251)
+++ pkg/R/Rd.R	2011-03-11 03:27:44 UTC (rev 252)
@@ -42,6 +42,63 @@
                        list(S4method=car(expression),
                             signature=cadr(expression)))
 
+##' Substitutions of questionable characters with a hacker-joke to
+##' boot.
+substitutions=c(
+  `!`='bang',
+  `"`='quote',
+  `#`='hash',
+  `$`='money',
+  `%`='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))))
+
 #' Make an Rd roclet which parses the given files and, if specified, populates
 #' the given subdirectory with Rd files; or writes to standard out.  See
 #' \cite{Writing R Extensions}
@@ -268,7 +325,9 @@
       name <- trim(name)
       if (!is.null(subdir)) {
         assign.parent('filename',
-                      file.path(subdir, sprintf('%s.Rd', name)),
+                      file.path(subdir,
+                                sprintf('%s.Rd',
+                                        translate.questionable.characters(name))),
                       environment())
         if (verbose)
           cat(sprintf('Writing %s to %s\n', name, filename))

Modified: pkg/TODO
===================================================================
--- pkg/TODO	2011-01-28 15:09:44 UTC (rev 251)
+++ pkg/TODO	2011-03-11 03:27:44 UTC (rev 252)
@@ -1,4 +1,104 @@
 # -*- mode: org; -*-
+* DONE translate filenames with non-alphabetic characters
+  CLOSED: [2011-03-10 Thu 18:58]
+  need translations for:
+
+  - =!=
+  - "
+  - =#=
+  - =$=
+  - =%=
+  - =&=
+  - '
+  - =(=
+  - =)=
+  - =*=
+  - =+=
+  - ,
+  - =-=
+  - =.=
+  - =/=
+  - =:=
+  - =;=
+  - =<=
+  - =
+  - =>=
+  - =?=
+  - =@=
+  - =[=
+  - =\=
+  - =]=
+  - =^=
+  - =_=
+  - =`=
+  - ={=
+  - =|=
+  - =}=
+  - =~=
+
+  not going to touch unicode.
+
+  #+BEGIN_SRC R :tangle test-substitution.R :shebang #!/usr/bin/env Rscript
+    library(gsubfn)
+    library(functional)
+    library(RUnit)
+    
+    substitutions=c(
+      `!`='bang',
+      `"`='quote',
+      `#`='hash',
+      `$`='money',
+      `%`='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'
+      )
+    
+    nil.if.lambda <- function(string)
+      if (nchar(string)) string else NULL
+    
+    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))))
+    
+    checkEquals(translate.questionable.characters('ha@@o'),
+                'ha-asperand-asperand-o')
+    checkEquals(translate.questionable.characters('nonquestionable'),
+                'nonquestionable')
+    checkEquals(translate.questionable.characters(''),
+                '')
+    
+  #+END_SRC
 * TODO document all tags
   when using roxygen, i have to resort to reading code to get the full
   list of tags; which should never have to be.



More information about the Roxygen-commits mailing list