How to use CLN : Class Library for Numbers - numerical

I need to do numerical calculations with high precision. There is a c++ library which is called "CLN",although i installed this package , but i do not know how to use it.
Is there an example program which shows how to use it?
Thanks

Something like that ?
http://www.warrenweckesser.net/software/cln/

Download the CLN source code from here, unpack it, and have a look into the examples/ folder. Alternatively, you may browse the same folder using gitweb.

Related

Best way to reference files outside directory in R

So I use a lot of custom built functions in R which I save in the documents folder in my pc. I would like to bring these functions into my R environment (I usually use source()). At the moment I use the entire file path, i.e. C:\Users\usename\documents\R functions\my_function.r and then create a quick access shortcut link in my project directory to these functions (for easy reference in case its needed). However I was wondering if there is a better way to reference these files. By better I basically mean shorter, or a way to source the files through the quick access shortcut. An alternative to this would be to create a secondary directory so I could just type source("&/my_function.r") (the "&" means secondary directory). This is just a minor inconvenience I think would make life easier if resolved. What do yo think? is this unnecessary complication? Is there anyone in a similar situation as me that has any tips for easily sourcing functions?
Thanks a lot!
If these are functions you often use, you could wrap them in a minimalistic package. Then your call would just be library("myhelpers") and you have all of them available.
Creating this package is quite easy. Assuming you use RStudio, you just:
Create a package: File -> New Project -> New Directory -> R Package
Give it the name you want e.g. "myhelpers"
Specify the folder it should be in
Then RStudio directly creates the package structure for you.
Now you have the package structure in your folder. It will look like this:
- DESCRIPTION
- man
- NAMESPACE
- R
- myhelpers.Rproj
You just have to put your .R files with the functions in the R folder. It does not matter, if the functions are in one file or in multiple files.
Then in R Studio go to the Tab "Build" and click "Install and and Restart". That's it!
Now in your other projects or R files you can just type and use all the functions you put in the R folder:
library("myhelpers")
var <- myfunction1(x)
If you later on want to edit your package functions or add new ones, you can just go to the package folder and click on myhelpers.Rproj and RStudio will open your package project for you. After your changes just click again Build -> Install and and Restart to update the package.
Here is also a short explanation with pictures. This is all you need to use your functions for yourself. The nice thing is, from there you can also go further if needed. E.g. add documentation to your functions. (then you could also have a help() page to your function).

How can I add a breakpoint to debug my R package without recompiling

When I develop a R package I endup doing the following thing:
load the latest build
use it
realize there is a bug in say function 'f_bug'
try to debug
I would be easy if I could just 're-source' f_bug and that the newly sourced version would be chosen (I'd rebuild the package clean latter).
But I cannot do that, it looks like the package::f_bug is always "chosen" by default when called within another package function.
Can I do such a thing ?
You can't use RStudio's convenient graphical breakpoints, but you can do the same thing using trace:
trace(package::f_bug, browser, at = insertion_point)
Here insertion_point refers not to line numbers but to a vector of substeps. From ?trace:
look at ‘as.list(body(f))’ to get the numbers
associated with the steps in function ‘f’.)
Another option might be to use utils::setBreakpoint which takes a file name and line number as arguments. See the help file for details.

C file does not work in my own R package?

I built my own package in R and created all my functions. Everything worked very well. Then, I want to include a .C files into my package.
I follow the structure in this link compiled code. Once I done that, my package stop working and cannot use it anymore.
I tried to fix it more than one time but nothing is happen. Then, I built another package and load my functions inside it (I was save a copy of my files).
Now I would like to start again but do not want to lose my function again. Any ideas?
Try to write your files first and make sure that they are work! Then build you package following the structures here.
Follow the structures step by step and you will be fine. Your package will set src file for you and all your other files.

Error when attempting to call a C++ .dll library in R

I have a library, let's say mylibrary.dll, that has c++ code that I want to run in R. I did this:
dyn.load("mylibrary.dll")
.Call("myfun")
I get:
Error in .Call("myfun") : C symbol name "myfun" not in load table
Now, I've seen several answers to similar problems, on here and on other websites, but when I attempted each solution, each seemed to be to require having access to the original source code, for example adding something like this: extern "C" to the C++ code or re-compiling the code in a certain way. All I have is a .dll file, and I'd like to use that directly to call from R the functions contained within it.
Solution: the name of the function was different than what I expected. I went to the thread that Alexey suggested in the comments, and from there was able to use one of the suggested tools (DLL export viewer) to get a list of the functions, where I found the correct name.
(Alas, I now need to figure out why R is locking up when I call the function, but my question here is done!)

How to know where a R package has been installed

Good moorning
I would like to know if there is a way to find where a package is installed.
Actually, I am currently documenting a package. In my package, I have a function called "read.myfile" which reads a specific kind of file (roughly like read.table).
I have an instance of this kind of file named "myfile.txt" in my package's folder. On my documentation, I want to run an executable example of this function.
That's why I need the path, where the user has installed the package. So with this path, I can obtain the path of the file "myfile.txt" and use the function "read.myfile" in the .Rd help file, which gives help about the function "read.myfile".
Thus my example will be executable wherever the user has installed the package.
I hope my message was clear.
I don't know if it's possible to do that, but if anyone knows, thanks for helping me.
Use the function system.file.
For example:
system.file(package="ggplot2")
[1] "C:/Users/Andrie/Documents/R/win-library/3.0/ggplot2"
You can use installed.packages and subset to get the only the location of the library in which it is installed:
installed.packages()["tools","LibPath"]
[1] "C:/Program Files/R/R-2.15.2/library"

Resources