About reading external files

Everything related to the development of modules in jamovi

by Jinghaom » Tue Mar 12, 2019 5:18 am

Hello

I am developing a package that uses stan for Bayesian analysis. Now there is a problem that stan needs to read the xxx.stan model file from outside for MCMC sampling.

I found that when I execute jmvtools:: install (), the model files are not packaged.
I now manually put the model file into the working directory of jamovi.
Jamovi-0.9.5.17-win64\bin

But I found that the working directory is not always here, so sometimes I can't find the model file (for example, the working directory is not there when I open the .omv file directly).

Any good suggestions?

Thank you
Jinghaom
 
Posts: 13
Joined: Mon Nov 05, 2018 1:05 pm

by jonathon » Tue Mar 12, 2019 5:26 am

so the stan file is a text file? if it's going into a package/module you can't rely on the user having the working directory set up properly.

to do this, you make use of the `inst` directory (https://cran.r-project.org/doc/manuals/ ... irectories)

so your module source will look like:

- DESCRIPTION
- NAMESPACE
- R
- jamovi
- inst

and whatever you put in the inst folder gets copied *into* the final module/package.

*then* to access this file, you use the system.file() function to resolve its path. https://www.rdocumentation.org/packages ... ystem.file

let me know if you get stuck

cheers

jonathon
User avatar
jonathon
 
Posts: 986
Joined: Fri Jan 27, 2017 10:04 am

by Jinghaom » Tue Mar 12, 2019 7:37 am

Hi jonathon

I solved the problem with your method.

thank you very much

jinghao
Jinghaom
 
Posts: 13
Joined: Mon Nov 05, 2018 1:05 pm


Return to Module development