About reading external files

Everything related to the development of modules in jamovi
Post Reply
Jinghaom
Posts: 13
Joined: Mon Nov 05, 2018 1:05 pm

About reading external files

Post by Jinghaom »

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
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: About reading external files

Post by jonathon »

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
Jinghaom
Posts: 13
Joined: Mon Nov 05, 2018 1:05 pm

Re: About reading external files

Post by Jinghaom »

Hi jonathon

I solved the problem with your method.

thank you very much

jinghao
Post Reply