[topic] URL特殊文字のエスケープ

URL用に特殊な文字をエスケープする。

Posted feedbacks - R

CGIwithRというライブラリーにアンエスケープの関数はあったのですが、
エスケープする関数はないようです。

> escape("~url quote/ほげ")
[1] "%7eurl%20quote%2f%82%d9%82%b0"
1
2
3
4
5
escape <- function(str){
    paste(sapply(unlist(strsplit(str, "")),
                 function(s){ifelse((regexpr("\\W", s, perl=TRUE)[1] > 0),
                                    paste("%", charToRaw(s), collapse="", sep=""), s)}), collapse="")
}

Index

Feed

Other

Link

Pathtraq

loading...