Comments (14)
Generally, using the R apply functions is sub-optimal. F# has far better functionality and syntax for apply-like operations as it has first-class support for functional programming. Similarly, F# and the .NET ecosystem has far better functionality than R for parallelism and asynchronous processing, so you don't need the parallel library.
However, where this gets thorny is when you want to execute some R function in parallel, which sounds like what you want to do. I've never tried running multi-threaded code using the R interpreter via the RProvider. My guess is that the R interpreter isn't properly thread-safe, but that is just a hunch.
We run R computations on a large compute grid, by using a .NET based distribution of the computation, and ensuring the R DLLs/libraries are available on each machine.
In terms of actually trying to use clusterApply, we don't currently have a way to pass a function - it's slightly tricky to implement something like that. The difficulty is that we can only pass a pure R function - we don't have a way to call back into .NET code. So we would need some way of doing that, probably using F# quotations. But it doesn't work right now.
from rprovider.
Thank you for your information. My main concern is computing performance. My work needs to intensively call R statistical fitting models to fit data like ARIMA and GARCH. Currently RDotNet does not yet support multithreading so .NET Parallelism does not work for RDotNet, nor for RProvider either. I did some performance tests to see how long it takes to run 1000 linear model fit for data of length 200/500/1000, or arima model fit and garch model fit for different lengths of data, in contrast with what takes to run the same fit in R. Unfortunately, in some cases it takes much longer time to run in F# (e.g. run 1000 iterations of arima model fit for data of length 50) than in R, which makes it desirable to call parallel computing in R. Is there any suggestion to boost the performance?
from rprovider.
I also faced with such case, when I need to define custom function and pass it to R.
Please look at Learning Kernels SVM. There we define custom kernel for svm and then pass this kernel for ksvm
as a parameter. As I see, I cannot do this using RProvider
.
Idea about F# quotations sound really cool (probably it is best option even if it is hard).
But probably we can define simple-to-use function
val execute : (string -> SymbolicExpression)
that execute R code from string and returns result back.
from rprovider.
You can probably do something using R.parse and R.eval, passing the necessary syntax to define a function to parse, then evaluating the result. I assume what you get back will be a SymbolicExpression representing a function, that you can pass into another function.
from rprovider.
I tried and it does not work:
let fun1 = R.eval("function(i) {mean(rnorm(i))}")
let nums = R.sapply(R.c(1,2,3),fun1)
which reports error:
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'function(i) {mean(rnorm(i))}' of mode 'function' was not found
The same error occurs when I use R.parse().
But I find a way like this:
First create an arbitrary R object like
let x = R.c(0)
Then we can use x.Engine to refer to REngine object the RProvider creates,
let fun1 = x.Engine.Evaluate("function(i) {mean(rnorm(i))}")
let nums = R.sapply(R.c(1,2,3),fun1)
This works perfectly.
from rprovider.
R.eval on a string produces something of type character. You have to call eval on the result of parse in order to get the expression evaluated. See http://stackoverflow.com/questions/1743698/r-eval-expression.
from rprovider.
Yes, thanks, it points out the problem exactly.
let fun1 = R.eval(R.parse(text="function(i) {mean(rnorm(i))}"))
let funs = R.sapply(R.c(1,2,3),fun1)
This works fine as suggested.
from rprovider.
Great!
So given that we have this solution, doesn't seem necessary to have an explicit function, but it probably deserves some documentation.
Ken - would you care to submit a pull-request with an appropriate change?
from rprovider.
I added a subsection “Creating and passing an R function” in the How-to wiki page
from rprovider.
Thanks!
I see you added this to the wiki, but now the main area of documentation is http://bluemountaincapital.github.io/FSharpRProvider/. @tpetricek - do you think we should disable the wiki (assuming that is possible). And can you advise how @renkun-ken can update the docs?
from rprovider.
I think we ported all existing content from the wiki to the new documentation, so I think we can disable it (there is a way to do that - but let's wait until @renkun-ken moves the new content).
@renkun-ken To add new content to the documentation, simply create a new F# Script file in the docs/content
folder (here) - follow the pattern used in tutorial.fsx
. If you start a comment with (**
, then it will be recognized as a Markdown block. Code snippets will be nicely formatted automatically next time we publish the documentation.
We are using F# Formatting and you can find more information here
from rprovider.
Thank you for your kindly help, @hmansell and @tpetricek! I just send a pull request for the newly added subsection of creating R functions to passing-data.fsx, as long as it is merged we may disable the wiki pages.
from rprovider.
I merged, and disabled the wiki. How do we regen the docs and push?
from rprovider.
I updated the published docs.
(To do this, just run build Release
from the windows command line - this rebuilds everything, including the documentation and then it should ask for a password to publish it.)
from rprovider.
Related Issues (20)
- Get CI etc working again HOT 9
- Tighter FsLab integration HOT 5
- Implement recommended community standards HOT 1
- Revise documentation for .net 5 release HOT 3
- Release a R v3.5+ legacy version for .net framework use HOT 1
- Remove requirement for R_HOME environment variable to be set
- Graphics are unresponsive on Windows and macOS HOT 2
- [Windows only] RProvider doesn't work with R > 4.0.2 HOT 7
- Replace "." with "_" in library names for consistency. HOT 1
- The RPovider is now at https://fslab.org/RProvider/ HOT 5
- Plugins not working with 2.0 beta
- Server fails to start on Apple Silicon
- Project build when referencing RProvider hangs forever (ubuntu-latest - github actions) HOT 2
- FSI printing for R SymbolicExpressions missing since change to #r nuget HOT 5
- 'Permission Denied' in some Github Actions CI scripts but not others
- Check code formatting with fantomas
- Docs build problems on windows github action HOT 1
- No Docs for how to extract values from test summaries HOT 3
- Running an fsx script from "Reading and writing RData files" with fsi throws a `System.Reflection.TargetInvocationException` exception. HOT 3
- Add support for running on aarch64 architecture HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rprovider.