[Rd] Replace back slashes with forward slashes?

From: Spencer Graves <spencer.graves_at_prodsyse.com>
Date: Wed, 29 Feb 2012 09:37:51 -0800

Hello, All:

       What can people tell me about converting back slashes to forward slashes in character strings?

       Several years ago, Prof. Ripley provided a solution, which I lost and have not been able to find.

       Below please find a function to do this. I do not find this very satisfactory, however, because it uses "scan" and therefore operates on an input not a character string. Unless someone suggests something better, I plan to add this to the "sos" package and issue a new release very soon. (The new release is needed, because the RSiteSearch capability has been modified in a way that breaks the current "findFn" core of "sos".)


back2forwardslash <- function (nmax = 1, pattern = "\\", replacement = "/") {

     x <- scan(what = character(), quote = pattern, nmax = nmax)
     x. <- gsub(pattern, replacement, x, fixed = TRUE)
     paste(x., collapse = " ")


(x <- back2forwardslash())


# nmax must be one more than the number of embedded blanks
(x3 <- back2forwardslash(3))

c:\u\a b\c d

Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San Josť, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com

R-devel_at_r-project.org mailing list
Received on Wed 29 Feb 2012 - 17:44:42 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 29 Feb 2012 - 18:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive