mrc-ide / odin.dust

Compile odin to dust
https://mrc-ide.github.io/odin.dust
Other
3 stars 1 forks source link

valid name assertion fails with incomprehensible error message #98

Closed chvandorp closed 2 years ago

chvandorp commented 2 years ago

Hi, I tried compiling a odin model with odin.dust and got a strange error message. I then found out that the problem was that the file name contained an underscore (as in odin_test.txt). However the string odin_test was not show in the error message:

model <- odin.dust::odin_dust("odin_test.txt") ## make sure the file exists

results in the following error

Error in assert_valid_name(ret$name) : 
  'ret$name' must contain only letters and numbers, starting with a letter

regards,

Chris

richfitz commented 2 years ago

Oohh, that is weird.

writeLines(c("update(x) <- 1", "initial(x) <- 1"),
           "odin_test.R")
odin.dust::odin_dust("odin_test.R")

The issue is that we create the name for the shared library from the filename, but we should really just work around that, and if we do throw an error should throw a better one than this...

richfitz commented 2 years ago

Ah, I remember now. dust uses pkgload and we create a little fake package behind the scenes. This means that the name of the model needs to be a valid C++ identifier, R identifier and (most annoyingly) R package identifier. I suspect I can relax the last one and then this issue will go away (https://github.com/mrc-ide/dust/issues/358)

richfitz commented 2 years ago

Can you please try with this version of dust: https://github.com/mrc-ide/dust/pull/359

With that installed (0.11.22) I believe this will work; at least it does for my toy example. Thanks for the report!