Where are the source-codes contained in the IDL-directory? - idl-programming-language

can someone tell me, where i can find the source-codes contained in the IDL-Directory.
In IDL one can run "demo". Under "Math and Statistics" -> "Math and Statistics Demo", there is as an example a polynomial fit. Where is the source-code for this polynomial fit contained within the idl directory?
best regards

So your answer has several parts. You can find the "demo" source code in your IDL installation, inside examples/demo/demosrc. If you want the source code to the actual polynomial fit routines, those will either be in source code inside the "lib" directory, or they might be written in C code for speed. The documentation will tell you if it is written in pro code.
For pro code routines, once you've compiled the routine, you can always use the "routine_filepath" command to find the source code location. Hope this helps!

Related

How to view mplus plots in r

I'm working on a project using programs r and Mplus. On Macs, the Mplus program doesn't allow you to load plots directly but it interfaces with r to do so. Sadly, I've followed the directions provided by the Mplus website but can't seem to locate the "source code" file that they casually refer to. I've searched my computer and the internet for an r file called "mplus.R" to no avail. Does anyone have experience with this?
Here are the two sources from Mplus I've been following:
https://www.statmodel.com/mplus-R/
http://www.statmodel.com/mplus-R/Mplus%20R%20tutorial.pdf
I've loaded the BiocManager package which is required to load the rhdf5 package but there are no functions for mplus listed in that second link. The answer must be in the mplus.R source code but I can't find it anywhere. Any help is much appreciated.
I found the source code right after sending off that question. I won't delete it incase someone might find this useful.
The mplus.R code required to view plots can be find in the first link posted in the question. It's under the section titled "The File mplus.R" but it must be copied and pasted into your r console or script and ran.

Are there any good resources/best-practices to "industrialize" code in R for a data science project?

I need to "industrialize" an R code for a data science project, because the project will be rerun several times in the future with fresh data. The new code should be really easy to follow even for people who have not worked on the project before and they should be able to redo the whole workflow quite quickly. Therefore I am looking for tips, suggestions, resources and best-practices on how to achieve this objective.
Thank you for your help in advance!
You can make an R package out of your project, because it has everything you need for a standalone project that you want to share with others :
Easy to share, download and install
R has a very efficient documentation system for your functions and objects when you work within R Studio. Combined with roxygen2, it enables you to document precisely every function, and makes the code clearer since you can avoid commenting with inline comments (but please do so anyway if needed)
You can specify quite easily which dependancies your package will need, so that every one knows what to install for your project to work. You can also use packrat if you want to mimic python's virtualenv
R also provide a long format documentation system, which are called vignettes and are similar to a printed notebook : you can display code, text, code results, etc. This is were you will write guidelines and methods on how to use the functions, provide detailed instructions for a certain method, etc. Once the package is installed they are automatically included and available for all users.
The only downside is the following : since R is a functional programming language, a package consists of mainly functions, and some other relevant objects (data, for instance), but not really scripts.
More details about the last point if your project consists in a script that calls a set of functions to do something, it cannot directly appear within the package. Two options here : a) you make a dispatcher function that runs a set of functions to do the job, so that users just have to call one function to run the whole method (not really good for maintenance) ; b) you make the whole script appear in a vignette (see above). With this method, people just have to write a single R file (which can be copy-pasted from the vignette), which may look like this :
library(mydatascienceproject)
library(...)
...
dothis()
dothat()
finishwork()
That enables you to execute the whole work from a terminal or a distant machine with Rscript, with the following (using argparse to add arguments)
Rscript myautomatedtask.R --arg1 anargument --arg2 anotherargument
And finally if you write a bash file calling Rscript, you can automate everything !
Feel free to read Hadley Wickham's book about R packages, it is super clear, full of best practices and of great help in writing your packages.
One can get lost in the multiple files in the project's folder, so it should be structured properly: link
Naming conventions that I use: first, second.
Set up the random seed, so the outputs should be reproducible.
Documentation is important: you can use the Roxygen skeleton in rstudio (default ctrl+alt+shift+r).
I usually separate the code into smaller, logically cohesive scripts, and use a main.R script, that uses the others.
If you use a special set of libraries, you can consider using packrat. Once you set it up, you can manage the installed project-specific libraries.

Using/Distributing pre-compiled files

I already asked this in the Julia community discourse but asking it here as expect to find different audience.
I created a simple function as below:
#MyFunction.jl
__precompile__()
function MyFunction(x)
y = x * 5
y * 5
end
And found the pre-compiled files saved as:
/Users/hasan/.julia/compiled/v1.0/MyFunction.jl
Can I use/distribute this pre-compiled file with my main function without using the original file source code itself?
These "compiled" files are only the lowering pass of Julia to byte code, which is not sufficient for stand-alone distribution. You might find this StackOverflow answer from Stefan Karspinski, one of the creators of Julia, useful for more details on the various layers of compilation inside Julia: https://stackoverflow.com/a/43456211/5504925
If you really want compiled code, your current best bet would be https://github.com/JuliaLang/PackageCompiler.jl. I'm not sure whether the package currently supports creating stand-alone binaries, or only intermediate forms, see also the introducting blog post by the author: https://medium.com/#sdanisch/compiling-julia-binaries-ddd6d4e0caf4.

Display Constraints Generated in CPLEX ILOG Studio

I would simply like to know whether it is possible to display all the constraints generated for a particular optimization problem in CPLEX ILOG Studio and how to do it.
I think that the best thing to do is to get CPLEX to save a copy of its model as a text file in the LP file format. Then you can look at the model with any text editor you want. You can also read that LP file back into the CPLEX command line interface and re-solve it. You can also of course edit that file and re-solve it, so you can explore in detail the effect of changing e.g. a variable's bounds or fixing its value.
To enable this (it's not obvious) you can add a settings file to your project in OPL Studio. Edit the settings file by double-clicking on it. Then inside that settings file, at the bottom of the tree look for Language -> Run, and there should be an entry for the Export format. Select 'LP'. Then add that settings file to your particular run configuration.
Obviously it will help if you set names on your variables and constraints too. Then it will be simpler to navigate around the LP file that gets generated.
Be aware that the LP file format will lose some precision in the numerical representation compared to the internal model inside CPLEX, so you may find slight differences from your original model and solution, but its not normally an issue if your model is numerically reasonable.

How to put an r script into a package

I'm writing my first R package and have made a successful build with documentation using roxygen2 and added data sets.
However, I would also like ship an example script with how I use the functions in the r package. But I don't know where to put it.
Let's say I have created MyPackage. I have put my function scripts in the /R folder. Let's say I have:
foo1.R
foo2.R
foo3.R
Somewhere I'd also like to put a script with my workflow. Let's say I have a file, MyWorkflow.R:
library(MyPackage)
load(file='inData.R') # Loads indata variables A, B and C
X=foo1(A)
Y=foo2(X,B)
Z=foo3(Y,C)
Can I do this? If so, where do I put it? Is it an OK procedure - or generally frowned upon?
Any help or thoughts are appreciated.
Thanks.
Carl
Edit:
I looked at the link on demo/ and exec/, but didn't understand the exec/ folder thing. Grateful if you could clarify/exemplify/point to good uses of...
If I understand correctly, I'm not looking for an example or demo/, since the script won't necessarily be executable without tweaking by the user (e.g. to provide input data or paths). I "just" want to add an example script showing how I work with these functions.
I realise I should probably dive into the world of vignettes, but have difficulty in finding the time/oomph/energy to do so.
I also saw that there's the inst/ folder. Could you shed some light on the different uses of these options or hint at good examples of where they've been used (I often find examples more informative than reading an explanatory text that's above my level - I often get the feeling of being like a dog looking at a ceiling fan ;)
Will add info to the GitHub README. Thx for good suggestion!
Created inst/Workflow_Example/workflow.R. Upon build & reload, a Workflow_Example folder was created in the library with workflow.R script in it.
In combination with an explanatory remark in the README, this looks like what I was after. Problem solved or am I not seeing something obvious? Am I e.g. violating conventions/conduct/good practice?
You could either put it in demo/ or exec/ depending on the format of the script. See here for more details. I would mention the workflow and where it lives in the README regardless, and if you host your code on Github, you could create a wiki to describe the workflow and place the script there. This would be similar to what nrussell has mentioned in a comment above.

Resources