Closed ThierryO closed 6 years ago
While oldenc should always be a data.frame, the condition to emit the error you mentioned is not clear.
> oldenc <- dbGetQuery(con, "SHOW client_encoding")
> oldenc
client_encoding
1 UTF8
> paste("SET CLIENT_ENCODING TO '", oldenc, "'", sep="")
[1] "SET CLIENT_ENCODING TO 'UTF8'"
The problem is due to a function as.character.data.frame()
is my own package
default R
> oldenc <- data.frame(client_encoding = "UTF-8", stringsAsFactors = FALSE)
> str(as.character(oldenc))
chr "UTF-8"
> paste("SET CLIENT_ENCODING TO '", oldenc, "'", sep="")
[1] "SET CLIENT_ENCODING TO 'UTF-8'"
with my function
> as.character.data.frame <- function(x, ...){
+ factors <- sapply(x, is.factor)
+ for (i in which(factors)) {
+ x[, i] <- levels(x[, i])[x[, i]]
+ }
+ return(x)
+ }
> oldenc <- data.frame(client_encoding = "UTF-8", stringsAsFactors = FALSE)
> str(as.character(oldenc))
'data.frame': 1 obs. of 1 variable:
$ client_encoding: chr "UTF-8"
> paste("SET CLIENT_ENCODING TO '", oldenc, "'", sep="")
Error in paste("SET CLIENT_ENCODING TO '", oldenc, "'", sep = "") :
non-string argument to internal 'paste'
When
oldenc <- dbGetQuery(new.con, "SHOW client_encoding")
returns a data.frame,sql5 <- paste("SET CLIENT_ENCODING TO '", oldenc, "'", sep="")
returns the error belowThis pull request converts
oldenc
to a character when it is a data.frame.