[R] "Special" characters in URI

Henrik Bengtsson hb at maths.lth.se
Tue May 3 13:40:49 CEST 2005


Gregor GORJANC wrote:
> Prof Brian Ripley wrote:
> 
>>On Tue, 3 May 2005, Gorjanc Gregor wrote:
>>
>>
>>>I am crossposting this to R-help and BioC, since it is relevant to both
>>>groups.
>>
>>I don't see the relevance to R-help.  But the answer to your subject is
> 
> Is it more rellevant for R-devel?
> 
> 
>>unambiguous: valid URLs do not contain `special' characters -- they must
>>be encoded.  See RFC1738 at e.g. ftp://ftp.funet.fi/pub/doc/rfc/rfc1738.txt
> 
> Yes, I understand that completely and I just wanted to know how other
> handle or have solved this issue. Having this in mind I am looking forward
> to your 'filePathToURL' function. Do you have any scratches of it already?
> What do you think about this scratch, which afcourse doesn't solve all
> "special" characters:
> 
> fixURLchar <- function(URL,
>                        from = c(" ", "\"", ",", "#"),
>                        to = c("%20", "%22", "%2c", "%23"))

Just a comment. It is much safer/easier to use named vectors for 
mapping, e.g.

  map <- c(" "="%20", "\""="%22", ","="%2c", "#"="%23")

/Henrik

> {
>   ## Checks
>   if (length(from) != length(to))
>     stop("Length of 'from' and 'to' must be the same")
> 
>   ## Core
>   for (i in seq(along=from)) {
>     URL <- gsub(pattern=from[i], replacement=to[i], x=URL)
>   }
> 
>   return(URL)
> }
> 
> 
> 
>>At some point (probably 2.2.0) I intend to ensure that the mapping to
>>file:// URLs that is done is a few places is encoded as necessary.  This
>>will likely result in a utility function filePathToURL or some such.
>>
> 
>




More information about the R-help mailing list