Ignoring the symbol ° in R devtools function document() - r

I would like to create a package for internal usage (not to distribute somewhere). One of my functions contains the line
if (data$unit[i] != "°C") {
It works perfectly in the script, but if I want to create the documentation for my package using document() from devtools, i get the error
Error in parse(text = lines, keep.source = TRUE, srcfile = srcfilecopy(file, path_to_my_code: unexpected INCOMPLETE_STRING
279: if (! is.na(data$unit[i]){
280: if (data$unit[i] != "
addition: Warning message:
In readLines(con, warn = FALSE, n = n, ok = ok, skipNul = skipNul) :
invalid input found on input connection 'path_to_my_code'
If I delete the °-character, document() works. But I need this character there, so this is not an option.
When using double-\ in the if-clause, my function doesn't detect °C anymore as shown here:
test <- c("mg/l", "°C")
"\\°C" %in% test
[1] FALSE
If I use tryCatch, the documentation is also not created.
Replacing "°C" by gsub(pattern = '\\\\', replacement = "", x = '\\°C') causes the function to crash at the double-\ .
How can I tell document() that everything is fine and it should just create the files?

Related

tdplyr - (TDR_E1001) using fastload

I am getting some weird errors, when I try to upload a data.frame to the Teradata database using td_fastload() in R.
The copy_to() method works for smaller sets without any issues, just takes a while... but td_fastload() for bigger sets don't work, here is what I am getting, what does this mean ?
my command is:
td_fastload(con, df = TEST55, table.name = "TEST55", overwrite = TRUE )
and the errors are:
Error: In value[[3L]](cond):
[tdplyr - (TDR_E1001)] Error: In value[[3L]](cond):
[tdplyr - (TDR_E1001)] Error in obtainRows(res, FALSE, params): Argument params class character differs from the required data.frame or list
In addition: Warning messages:
1: In td_fastload(con, df = TEST55, table.name = 'TEST55', overwrite = TRUE):
[tdplyr - (TDR_W1011)] Setting 'overwrite = TRUE' will drop existing table 'TEST55' and recreate it with new schema.
2: In sprintf(gettext(fmt, domain = domain, trim = trim), ...) :
one argument not used by format 'Error in obtainRows(res, FALSE, params): Argument params class character differs from the required data.frame or list
'
3: In sprintf(gettext(fmt, domain = domain, trim = trim), ...) :
one argument not used by format 'Error: In value[[3L]](cond):
[tdplyr - (TDR_E1001)] Error in obtainRows(res, FALSE, params): Argument params class character differs from the required data.frame or list```

Meaning of this warning; "Warning message: In get(object, envir = currentEnv, inherits = TRUE) : restarting interrupted promise evaluation"

I have written a function in R which extracts data from a database and builds a new table.
My new table is labeled with the date of the extract (build_date_0).
When I'm debugging my function I get the following warning when I look at my date string:
Browse[2]> build_date_0
[1] "2019-05-01"
Warning message:
In get(object, envir = currentEnv, inherits = TRUE) :
restarting interrupted promise evaluation
Questions:
What does this warning mean / what is happening (step-by-step/basics)?
Should I care?
In general how can I find out more about this error?
This is my code:
build_account_db = function(conn = connection_object
,various_inputs = 24){
browser()
# create connection objects
tabs_1 = dplyr::tbl(conn,in_schema("DB_1","VIEW_W") # some table
# create date string
build_date_0 = lubridate::today() %>% as.character()
build_date = str_replace_all(build_date_0,"-+","_")
db_name_1 = paste0('DATABASE.tab_1_',build_date)
db_name_2 = paste0('DATABASE.tab_2_',build_date)
# build query
query_text_1 = tabs_1 %>% select(COL_1) # some query
query_text_1 = tabs_1 %>% select(COL_2)
# build new tables
create_db = DBI::dbSendQuery(conn_t,paste('CREATE TABLE',db_name_1,'AS (',query_text_1,') WITH DATA PRIMARY INDEX (ID_1)'))
create_db2 = DBI::dbSendQuery(conn_t,paste('CREATE TABLE',db_name_2,'AS (',query_text_2,') WITH DATA PRIMARY INDEX (ID_1)'))
}
When I check a variable, I may or may not get this warning (it varies, even if I restart R, and run my code again with a cleared environment)
Browse[2]> build_date
[1] "2019-02-28 11:00:00 AEDT"
Warning message:
In get(object, envir = currentEnv, inherits = TRUE) :
restarting interrupted promise evaluation
What I've tried: I read this question, but it's more about suppressing the error. Also, google.
I found this link on promises and evaluation in R helpful for a related problem: https://mailund.dk/posts/promises-and-lazy-evaluation/. I wonder if after build_date_0 = lubridate::today() %>% as.character() if you add a call to just build_date_0 if that would solve the promise? Good luck!

how to get document() to accept µ

I have been using this code
nutList <- gsub("_µg","",nutList, fixed = TRUE)
to remove the string "_µg" from the variable nutList for at least a year and have had no problems. Now I'm trying use document() to see where I have problems in getting ready for a package.
Error in parse(text = lines, n = -1, srcfile = srcfile) : [filename] : unexpected INCOMPLETE_STRING
nutList <- gsub("_
It appears that document() doesn't like the µ that is there. How can I modify the code so it is accepted?

Error in gsub is too long with Arabic language in R

I am doing text mining in R with Arabic language
And use gsub function but I got an error as shown here
Error in gsub("^\\x{0627}\\x{0644}(?=\\p{L})", "", x, perl = TRUE) :
invalid regular expression '^\x{0627}\x{0644}(?=\p{L})'
In addition: Warning message:
In gsub("^\\x{0627}\\x{0644}(?=\\p{L})", "", x, perl = TRUE) :
PCRE pattern compilation error
'character value in \x{} or \o{} is too large'
at '}\x{0644}(?=\p{L})'
here is my code
x<-("الوطن")
# Remove leading alef lam with optional leading waw
m <- gsub('^\\x{0627}\\x{0644}(?=\\p{L})', '', x, perl = TRUE)
anyone can help me ?
Finally I solved the problem ,
the problem is : when I import data in Arabic language as csv then apply gsub I get the error
Error in gsub("^\\x{0627}\\x{0644}(?=\\p{L})", "", x, perl = TRUE) :
invalid regular expression '^\x{0627}\x{0644}(?=\p{L})'
In addition: Warning message:
In gsub("^\\x{0627}\\x{0644}(?=\\p{L})", "", x, perl = TRUE) :
PCRE pattern compilation error
'character value in \x{} or \o{} is too large'
at '}\x{0644}(?=\p{L})'
I figure out that I need to save the data with encode= UTF-8
then read it also with encode= UTF-8 Then change the Local .
like this code :
Sys.setlocale("LC_CTYPE","arabic")
[1] "Arabic_Saudi Arabia.1256"
> write.csv(x, file = "x.csv" , fileEncoding = "UTF-8")
y<-read.csv("C:/Users/Documents/x.csv",encoding ="UTF-8")
> Sys.setlocale("LC_CTYPE","arabic")
[1] "Arabic_Saudi Arabia.1256"
it seems to me the only problem is your quotation marks:
> x <- "الوطن"
> gsub('^\\x{0627}\\x{0644}(?=\\p{L})', '', x, perl = TRUE)
[1] "وطن"
also, check for your OS locale as I've experienced some similar issues when trying to process Hebrew text while my Windows locale was set to US.

RStudio fails to read GBP pound sign

After a bit of a gap I updated RStudio and all packages this morning.
I have a little function that I use to prettify currencies
currency <- function(n, k=FALSE) {
n <- ifelse(!k, str_c("£", comma(round(n,0))), str_c("£", comma(round(n/1000,0)),"k"))
return(n)
}
It now fails to parse - the problem is the £ sign.
Error in parse(text = lines, n = -1, srcfile = srcfile) :
[path]/plot_helpers.R:72:
25: unexpected INCOMPLETE_STRING
71: currency <- function(n, k=FALSE) {
72: n <- ifelse(!k, str_c("
^
In addition: Warning message:
In readLines(con, warn = FALSE, n = n, ok = ok, skipNul = skipNul) :
invalid input found on input connection '/home/richardc/ownCloud/prodr/R/plot_helpers.R'
However I can run the code within the editor and it works fine. What is causing readLines to fail in this way ?
After some messing about today, I realise that the problem is in devtools. To recap here is a test project testencr.prj:
library(stringr)
library(devtools)
main <- function(n) {
n <- str_c("£", n)
return(n)
}
I can run the code fine from the console, but when I use devtools it barfs on the UTF-8 character:
> devtools::load_all()
Loading testencr
Error in parse(text = lines, n = -1, srcfile = srcfile) :
/home/richardc/ownCloud/test/R/test_enc.R:6:14: unexpected INCOMPLETE_STRING
5: main <- function(n) {
6: n <- str_c("
^
In addition: There were 27 warnings (use warnings() to see them)
But when I add a specific encoding into the DESCRIPTION
Encoding: UTF-8
It is all fine (this notwithstanding the project defaults are UTF8)
Loading testencr
There were 36 warnings (use warnings() to see them)```
I was having the same problem, specifically in a Shiny app (not the rest of the time). I managed to solve it by using this unicode instead of £:
enc2utf8("\u00A3")

Resources