OHDSI Home | Forums | Wiki | Github

Bug in SqlRender when applying unit tests?

Dear all,

I’m struggling with a unit test where I try to use the SqlRender package. A minimal reproducible example would be

test_that( "a test", {
sql <- SqlRender::loadRenderTranslateSql("test.sql", dbms="sql server", packageName="SomePackageName")
})

I’ve put a file named test.sql containing nothing in inst/sql/sql_server and built the package, and when I run devtools::test() there are two warnings followed by a error message:

file("") only supports open = “w+” and open = “w+b”: using the former
text connection used with readChar(), results may be incorrect
invalid ‘nchars’ argument

It believe it’s the nchars argument in the line “readChar(pathToSql, file.info(pathToSql)$size)” that causes the error. If the test is run line-by-line in my console, everything works fine.

I found the same error message on Eunomias website, but it could be totally unrelated I guess: https://ohdsi.github.io/Eunomia/reference/createCohorts.html

I’ve also posted this on SqlRenders github page, and will link to the answer if it’s answered there first.

It looks like it can’t find the file “test.sql” in the inst/sql/sql_server folder of your package with name ‘SomePackageName’. Can you verify the file is there? Did you build your package before running this function?

Thanks for your reply.

Yes the file is there and yes, the package has been built (CTRL + SHIFT + B) before testing. Here are some screenshots in case that’s helpful for you:

The test:

And the test-output, with a red arrow pointing at the the test.sql-file

It seems like it is actually something weird with the devtools test command? The test passes when you run R check, and the function also works without problem if you just call

SqlRender::loadRenderTranslateSql("test.sql", dbms="sql server", packageName="IcTemporalPatternDiscovery")

in the console

You mean that you replicated the bug? :slight_smile:

It works fine in the console, but I’m afraid “R check” (CTRL - SHIFT - E / devtools::check()) does not pass on my computer. It’s related to some Java 32-bit issue which we know of but plan to live with as long as we have 64-bit working. But I guess it would be good to know if others with functioning Java 32 bit have the same issue with devtools, just to rule that out.

I have seen this issue on our environments several times. Try configuring RStudio Build > Project Options > Build Tools to use the --no-multiarch option.

Thanks for pointing that out. I had included no-multiarch on the build at some point, but not on the check. Now it’s just the nchar-thing from readChar that fails.

Are you saying you still can’t complete R Check on the develop branch of IcTemporalPatternDiscovery? It runs fine in my environment (64-bits Windows).

I’m afraid so. I pulled the current version from github, built it and ran devtools::check(args = c(’–no-multiarch’)):

image

and this is the “Eunomia example works”-test, after I commented out the irrelevant stuff:

This runs fine in my environment (it does generate 5 notes, but those can be fixed).

Your error message screenshot shows “test_check()”, which I’m not familiar with. Are you on the latest version of devtools?

Schuemie;

I updated R, Rtools, devtools and noticed an error message about the length of the filepath to the file not found.

“Tarballs are only required to store paths of up to 100 bytes and cannot store those of more than 256 bytes, with restrictions including to 100 bytes for the final component.”

Changing the name to a shorter one fixed the error. Thanks a lot! :slight_smile:

t