From 0b14bb876b00393316d6a87950638fba733bc70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1lmar=20=C3=9Eorsteinsson?= Date: Fri, 3 Dec 2021 15:42:37 +0000 Subject: [PATCH] Added a text argument to read.px to allow parsing a PX file from text like in the native read.table function --- R/read.px.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/R/read.px.R b/R/read.px.R index e8cc2e0..d6247a6 100644 --- a/R/read.px.R +++ b/R/read.px.R @@ -31,7 +31,14 @@ ################################################################# read.px <- function(filename, encoding = NULL, - na.strings = c('"."', '".."', '"..."', '"...."', '"....."', '"......"', '":"')) { + na.strings = c('"."', '".."', '"..."', '"...."', '"....."', '"......"', '":"'), + text) { + + if (missing(filename) && !missing(text)) { + filename <- textConnection(text, encoding = "UTF-8") + encoding <- "UTF-8" + on.exit(close(filename)) + } ## auxiliary functions ## @@ -61,7 +68,7 @@ read.px <- function(filename, encoding = NULL, "latin1", "CP437") # comprobado en debian y osx } - a <- scan(filename, what = "character", sep = "\n", quiet = TRUE, fileEncoding = encoding) + a <- scan(filename, what = "character", sep = "\n", quiet = TRUE, encoding = encoding, fileEncoding = encoding) # modification by fvf: 130608 a <- paste(a, collapse = "\n") # Se mantienen "CR/LF luego se quitaran selectivamente