Hello, I need to convert an R vector to a python array. Essentially, I got a vector of strings where each element must be enclosed in single quotes. The problem is that each closing single quote should contain a comma. What is the regex trick to do that? I tried with: ``` > (raws = c("field_1", "field_2", "field_3")) [1] "field_1" "field_2" "field_3" > (items = sQuote(raws)) [1] "'field_1'" "'field_2'" "'field_3'" > gsub("\'[:blank:]", "\',[:blank:]", items, ignore.case = FALSE, perl = FALSE) [1] "'field_1'" "'field_2'" "'field_3'" > cat("python_Array = [", domain_list, "]\n") python_Array = [ 'Index' 'Endpoints' 'Confounders' 'Arboexposure' ] ``` To note that `python_Array` does not have commas between elements and `gsub` did not do anything...
Thank you ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.