Closed John-R-Wallace-NOAA closed 1 year ago
Thanks @John-R-Wallace-NOAA for reporting the difficulty you are having with PullCatch.PacFIN()
.
sQuote(q = FALSE)
in the three calls to this function to force quotes to not be fancy.stopifnot()
call not working.require(RODBC)
call in an if statement to warn users that they cannot use the function unless they have the necessary packages.The fancy quotes are the default in R. I checked many R sessions including Linux and the new Win ver 4.3, since I was curious. Being the default, when I tried the function it didn't work. I'm curious if you were using another package or function that changed the default of fancy quotes.
@John-R-Wallace-NOAA, my R session doesn't use fancy quotes. It looks like users have control over the default: https://stat.ethz.ch/R-manual/R-devel/library/base/html/options.html.
I have
options()$useFancyQuotes
[1] FALSE
@iantaylor-NOAA and I meet briefly on Friday and found that it was Radian which has the useFancyQuotes set to FALSE, but that his Rqui console had useFancyQuotes set to TRUE. A search on the Web directed my to the last paragraph of the help Details section for sQuote(), which states:
"To work around this [the correct rendering of fancy quotes], the default for options("useFancyQuotes") is FALSE on Windows except for the Rgui console. There fancy quotes work with the default Courier New font and more elegantly with Lucida Console and default East Asian fonts, but directional double quotes are missing in raster fonts such as Courier and FixedSys."
Hence both R.exe and Radian, neither of which are based on Rgui, have useFancyQuotes set to FALSE as the default.
@John-R-Wallace-NOAA I think we can just set sQuote(q = FALSE)
in the three instances that it is used within {PacFIN.Utilities} to get around this issue, right? Also, I am reopening this issue because I haven't fixed the stopifnot()
call that you kindly reported was not working.
Setting sQuote(q = FALSE) in PacFIN.Utilities() will work fine.
My bad for not separating out the issues. :-/ The thought did cross my mind. :-)
RODBC::sqlQuery() cannot handle fancy quotes
only standard quotes <' '> inside of double quotes <" "> See the help for sQuote().
So this works:
but not:
nor:
sQuote() uses getOption("useFancyQuotes"), the default of which is TRUE in R, but a user may have changed it regardless.
The ways I got PullBDS.PacFIN() to work is to
Change the first line of PacFIN.Utilities:::sql_bds() so that q was forced to be FALSE:
or
The current options() needs to be saved in PullBDS.PacFIN() and restored on exit:
Note also that the error returned by PacFIN.Utilities:::getDB() was (note the fancy quotes):
This made NROW(data_raw) return a 2 which passed:
nrow(data_raw) > 0 returns:
which strangly also passes stopifnot()
Something like this would work (a tibble is also a data frame):
Examples:
Lastly, I just installed R ver 4.3, and that fresh install revealed that the RODBC also needs to be a required package.