Skip to content

#include support in stancjs #1430

@WardBrian

Description

@WardBrian

Is your feature request related to a problem? Please describe.

stanc.js often runs in environments like v8 where the file system is not available, and so it currently cannot handle #include statements. This limits its ability to be used for tasks like formatting, and compiling requires preprocessing outside of the compiler which leads to bugs and worse error messages.

Describe the solution you'd like

The stanc() function could accept a final argument which is a mapping from file paths to a string of their contents, e.g if i had a stan model foo.stan,

functions {
#include <helpers/bar.stan>
}
// ...

I could invoke stanc() like

stanc("foo", fooCode, arguments, {"helpers/bar.stan": barcode});

Describe alternatives you've considered
In contexts where the file system is actually available, like Node, we could just use it directly.

Additional context

Properly preparing a call to the above would require some work based on the include-paths argument the user supplied. Of course, you could over specify the final argument and include the text of all .stan files in the directory - perhaps a bit slower, but would work.

@andrjohns @hsbadr - does this sound like something RStan would use if it was supported

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions