Skip to content
Prev 69002 / 398502 Next

"Special" characters in URI

Prof Brian Ripley wrote:
Is it more rellevant for R-devel?
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"))
{
  ## 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)
}