Calling a custom function in Scilab - scilab

I'm fairly new to Scilab, and I'm trying to write a simple function and call it.
How can I write a function in a .sci file in some arbitrary directory and then call it? MATLAB does this automatically. I read a ton of posts talking about using "Execute->Load into scilab" and getf, but none of those are present in my version of Scilab (5.3.3). So how in the world can I do this?

exec filelocation\yourFile.sci;
should do it

Related

How can I generate files from Rust procedural macros?

I am building an extension API for R in Rust. I annotate my functions with a procedural macro to generate C wrappers with the appropriate conversion and error handling:
use extendr_api::*;
#[export_function]
fn hello() -> &'static str {
"hello"
}
This generates a C function hello__wrapper__ that is callable from R
using the .Call mechanism.
In addition to this, we need to generate a NAMESPACE file for the R
metatdata:
export(hello)
useDynLib(libhello, "__wrap__hello")
And a file lib.R
hello <- function() {
.Call("__wrap__hello")
}
What is the simplest way to extend cargo or rustc
to write this additional information? I'm guessing
that writing a file from the procedural macro code is
a bad idea.
From what I understand, procedural macros generate code at compile time, but it has to be valid Rust code. I do not think that a procedural macro is the way to go in this case.
One possible solution is to create a script that will go through and find your exported functions in the Rust file and generate the 2 extra files you need. You could make a build script that runs before compiling if you want to do all the parsing in Rust, otherwise I would suggest something like Python.

How to call a function from another folder in julia

I am new in Julia and saying good bye to MATLAB, The issue here is that I am trying to set a script with all my functions where I can go later and perform some operations.
I have tried to do so in a MATLAB style, I also tried to read the documentation, but neither help that much.
So the question here is: how do I set a .jl file in another folder so that I can call this file later on in Julia?.
Hint: I am using Atom as an editor
KR
Rubén
You can include any .jl file in a Julia session:
include("/path/to/my/jl/file/functions.jl")
Afterwards, all the function definitions etc. in functions.jl are available.

Rcpp: Save compiled function as Robj

If I define a function in R, I can save the function object using the save function. Then I can load that function object using the load function and use it directly. However, if I have a rcpp function, and if I try to save the compiled version and load it back to the memory, I can no longer use that function object directly. Is this even possible? The reason I ask is because it takes a while to compile the function, and if there is a way to avoid that cost every time I launch an R environment, that will be great. Thanks!
No, in general you cannot serialize (and hence save) a function compiled with cxxfunction() or sourceCpp(). You need to freshly compile it, unless you place it in a package. Which is why packages are the way to go to really install your compiled code beyond quick experimentation.

Organizing R's work in functions and subfuctions

My aim is to better organize the work done by a R code.
In particular it could be useful to split the R code I have written in different R files, perhaps with each R file accomplishing to a different task. I have in mind what we can do in Matlab with different M files, where we can easily call functions written in different M files directly from the main code.
Is it useful to write this R files in the form of functions?
How can we call these R files /functions in the main code?
Thanks
You can use source("filename.R") to include the file in your main script.
I am not sure if there is a ready function to include an entire directory, but it is straightforward to write using list.files() and then call source dynamicly for each filename. You can also filter files to only list *.R for example.
Unless you intend to write an R package, you should rethink your organization. R is not Matlab, thank goodness! You can place as many functions as you wish into a single file, and make them all available in your environment with source foo.r . If you are writing a collection of generic functions and don't want to build a package, this really is the cleaner way to go.
As a side thought, consider making some of your tools more flexible by adding more input arguments. You may find that you don't really need so many separate functions/files. As a trivial example, if you have some function do_it_double , another do_it_integer , and yet another do_it_character , all of which do basically the same thing, just merge them into a single do_it_all(x,y,datatype='double') and override the default datatype as desired. (I know this can be done with internal input validation. I'm just giving an example)
Your approach might be working good. I would recommend to wrap the code in a function and use one R file for one R function.
It might be interesting to look at the packages devtools and ProjectTemplate which aim to help organizing R code.

plotting data in R from matlab

I was wondering if it is possible to work between matlab and R to plot some data. I have a script in matlab which generates a text file. From this I was wondering if it was possible to open R from within matlab and plot the data from this text file and then return to matlab.
For example, if I save a text file called test.txt, in the path 'E:\', and then define the path of R which in my case will be:
pathR = 'C:\Program Files\R\R-2.14.1\bin\R';
Is it possible to run a script already written in R saved under test1.R (saved in the same directory as test.txt) in R from matlab?
If you're working with Windows (from the path it looks like you are), you can use the MATLAB R-link from the File Exchange to pass data from Matlab to R, execute commands there, and retrieve output.
I don't use R so this is not something I have done but I see no reason why you shouldn't be able to use the system function to call R from a Matlab session. Look in the product documentation under the section Run External Commands, Scripts, and Programs for this and related approaches.
There are some platform-specific peculiarities to be aware of and you may have to wrestle a little with what is returned (though since you are planning to have R create a plot which is likely to be a side-effect rather than what is returned you may not). As ever this is covered quite well in the product's documentation
After using R(D)COM and Matlab R-link for a while, I do not recommend it. The COM interface has trouble parsing many commands and it is difficult to debug the code. I recommend using a system command from Matlab as described in the R Wiki. This also avoids having to install RAndFriends.

Resources