Skip to content

Avoid warning with connection observer callback conditions eval - #494

Merged
detule merged 5 commits into
r-dbi:mainfrom
meztez:patch-1
Nov 9, 2022
Merged

detule merged 5 commits into
r-dbi:mainfrom
meztez:patch-1

Conversation

@meztez

@meztez meztez commented May 26, 2022 •

Copy link
Copy Markdown
Contributor

In R 4.2.0, when dbConnect is called within RStudio using something like:

odbc::dbConnect(odbc::odbc(), "DSN")

In

odbc/R/Driver.R

Line 123 in dee7ae0

as.character(expr[[1]]) %in% c("<-", "=") &&
,
as.character(expr[[1]]) will have values [1] odbc :: dbConnect and condition evaluates to FALSE FALSE FALSE thus cause a warning similar to

warning messages from top-level task callback '1'
Warning message:
In is.call(expr) && as.character(expr[[1]]) %in% c("<-", "=") :
  'length(x) = 3 > 1' in coercion to 'logical(1)'

I suggest using tail with a single element to return the expr name to the right if the ::.

When called using something like:
```
odbc::dbConnect(odbc::odbc(), "DSN")
```

`as.character(expr[[1]])` will print something like `[1] odbc      ::          dbConnect` which evaluate to FALSE FALSE FALSE and cause a warning similar to

```
warning messages from top-level task callback '1'
Warning message:
In is.call(expr) && as.character(expr[[1]]) %in% c("<-", "=") :
  'length(x) = 3 > 1' in coercion to 'logical(1)'
```
@JannesRed

Copy link
Copy Markdown

Not sure what it would take to get this reviewed and approved?

@detule

detule commented Nov 8, 2022

Copy link
Copy Markdown
Collaborator

Hi -

Thanks for the submission. Tailing could work. Alternatively, rather than converting the expression to character, it may be better converting the assignment operators to expressions. Something like:

op <- expr[[1]]
identical(op, quote(`<-`)) || identical(op, quote(`=`))

Please also add a bullet in the NEWS markdown file highlighting the fix.

Thanks again

Comment thread R/Driver.R Resolved
Comment thread R/Driver.R Resolved
@detule
detule merged commit da7b27b into r-dbi:main Nov 9, 2022
@detule

detule commented Nov 9, 2022

Copy link
Copy Markdown
Collaborator

Thanks again!🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants