I'd like to embed R into a c++ winforms app. It will output the graphs to a pictureBox, and output the numbers to a richTextBox. It takes commands from a textbox. I tried the header file RInside.h, but there is no such file.
Pseudo code:
#include <someDirToImbedR>
ExecuteButton_Click(args) {
RExecute(commandTextBox->Text);
outputGraphPictureBox->Load(output_graph);
richTextBox1->Text = OutputString;
}
I found this post on SO concerning (may be) the same problem.
Here is the Link to a repository by Dirk Eddelbuettel. It has even sample code in c++ to try for yourself.
Also this Link might be helpful.
Hope this can bring you on track. Unfortunately I personally used R only in C#.
Related
I have a C++ program that parses a binary file and outputs a std::string. I would like to call this function directly from Julia and convert the steam into a DataFrame. I need it to work in Linux and Windows. Currently, I have the program write the output to a text file, and then I read it into Julia. Cxx is no longer supported, and trying to get CxxWrap to work has been an exercise in frustration.
Toy Problem:
If someone could show me how to call the code below from Julia, that would be awesome.
// the example from https://github.com/JuliaInterop/CxxWrap.jl
#include <string>
std::string greet()
{
return "hello, world";
}
There's a new package which might fit your needs here:
https://github.com/eschnett/CxxInterface.jl
It is intended as a successor to Cxx.jl and more stable, so I'd recommend giving it ago although I haven't tried it myself!
I use MinGW64 to compile c++ programs. But since I upgraded to Windows 10, I found my c program output Chinese will be garbled code.
I follow the online method, adding a code in the program header: SetConsoleOutputCP(65001);, then it fixes. but I think it's so troublesome to do this for each c++ program. What should I do?
I think this is my system's problem, the same code in Windows 7 is not a problem, I just want to find a more convenient solution instead of adding the same code to every file
There's the code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
SetConsoleOutputCP(65001);
cout << "文本" ; //Output will be garbled code if there's no line above
return 0;
}
The console in most operating systems only expects ASCII character input. In order to show some other char set you have to specify that in your code. The SetConsoleOutputCP command sets the "code page" windows should read from. By the way not all versions of windows have the same code for this command.
Please refer to the documentation found here.
The documentation suggests using EnumSystemCodePages to make sure the code for that language exists on that system.
P.S.
Your English is very good :)
EDIT
I tested your code on my computer with Visual Studio 2019 and got the following
Warning C4566 character represented by universal-character-name '\u6587' cannot be represented in the current code page (1255)
even with the SetConsoleOutputCP command you added. I assume you need to have chines installed for this to work. The problem is that I don't have the relevant code page for the windows console to look in for the char set. see this answer and this answer.
I have looked extensively in the net, yet not found exactly what I want.
I have a big simulation program that outputs results in a MATLAB M-file (let's call it res.m) and I want to plot the results visually.
I want to start the simulation with C++ many times in a row and therefore want to automatize the plotting of the results.
I come up to two options:
Execute from C++ an Octave or MATLAB script that generates the graph.
-> Haven't found anyone who managed to do so
Use the Octave source files to read the res.m file and output them after with whatever plotting C++ tool.
-> Theoretically possible but I get lost in those files
Is someone able to solve this? Or has a better, easier approach?
The answer is to execute through the terminal.
I didn't manage to actually run a octave script from my c++ program directly, but there is a way around messing with/through the terminal and a extra Octave file. I used in my cpp:
string = "octave myProgr.m"
const char *command = str.c_str();
system(command);
myProgr.m is the script that plots the res.m file
I'm new to coding C++ programs in Visual Studio. When I am coding C# programs in VS, code formatter changes code that looked like this
for(int i= 0; i<(n+ m) ; i++){
}
into
for(int i = 0; i < (n + m); i++)
{
}
which is way easier to read. When I write the same thing in C++, nothing happens. I tried to select the text and press Ctrl+E, F, but that didn't work. Is there a way to improve the C++ code formatter in visual studio?
Visual Studio can't format C++-Code. Maybe there is a VS extension. I searched a long time, but never found a suitable one for free.
A very good, free, but not easy to use code formatter is GreatCode. Its a command line tool.
You can configure it as "External Tool":
After unpacking GreatCode on your HD just go Tools->External Tools->Add and insert the following settings...
Whenever you call that Tool, the actual opened file is being formatted.
You can configure GreatCode as you like in the gc.cfg. I tried many options, some are easy, some are complex.
If you want a Microsoft-like looking, just use my settings as a template and fine tune yourself:
-code_constructor_style-1
-code_split_fctdef_style-5
-code_split_decl_style-2
-overwrite_read_only-
-verbose-
-tab_out-
-space_if-
-space_return-
-space_fctcall_inparam-
-no-space_fctcall_firstparam-
-no-space_cast_after-
-space_affect_style-0
-space_autoaffect_style-0
-code_len-180
-code_keep_more_empty_lines-
-code_decl_access_to_type-
-code_decl_break_template-
-code_remove_return_paren-
-code_align_max_blanks-80
-code_class_access_eol_after-1
-code_class_access_eol_before-1
-code_split_fctcall_style-1
-code_constructor_style-1
-no-code_split_bool_before-
-no-stmt_concat_else_if-
-no-stmt_decl_remove_empty-
-no-stmt_concat_if_remove_empty-
-no-stmt_concat_else_if-
-stmt_force_brace-1
-stmt_break_dowhile-
-stmt_switch_style-1
-stmt_switch_eol-0
-stmt_class_indent-0
-stmt_static_init_style-2
-stmt_concat_inline_class-
-pp_align_to_code-
-pp_style-1
-pp_align_breakline-
-no-cmt_first_space_cpp-
-cmt_dont_modify-
-no-cmt_add_class_access-
-no-cmt_add_gc_tag-
-no-cmt_add_fct_def_class-
-no-cmt_decl_before-
-no-cmt_decl-
-no-cmt_first_line_break_first-
-no-cmt_first_line_break_last-
-no-code_split_bool_before-
-catch_eol_before-1
-no-stmt_decl_remove_empty-
-no-cmt_add_fct_def_class-
-no-cmt_add_class_access-
-no-stmt_break_alone-
-stmt_concat_inline_class-
-cmt_keep_cpp-
Good luck!
I use exactly the same approach as DirkMausF except the formatting tool itself. I would suggest you to use Artistic Style formatter:
http://astyle.sourceforge.net/
It is well documented and comes with a lot of predefined formatting styles so it is very easy to use.
If you have cash to spend, you might want to look in to Visual Assist. See also, this question.
For a long time, I was writing all the C++ code in Netbeans and I was compiling it in Visual Studio. Netbeans is formatting code perfectly (with ALT+SHIFT+F) and there are many formatting options.
Could anyone give me a suggestion or an example of how I would loop through the samples of CAF (Core Audio Format) file? Like taking the first 1000 samples and changing them to 0?
Something like:
for(int i=0; i < numberOfSamples; i++)
{
cafFile.sample[i] = methodThatUsesSampleValue(cafFile.sample[i]);
}
Keep in mind:
I don't need to do this live. No buffers, etc. needed.
I would like to do this in C, C++ or Objective-C.
Would like to be able to use the code on the iOS platform.
Any help appreciated!
The libsndfile C++ library is well-known and provides -among lot of other functions - a function to read AIFF-files: http://www.mega-nerd.com/libsndfile/, the lib is distributed under the "Gnu Lesser General Public License". I don't know if that is an issue.
Recently I stumbled over the amazing OpenFrameWorks library: http://www.openframeworks.cc/about And I know it compiles on MacOS and iPhone. Amongst many(!) other libs it come with an interface to rtAudio: http://www.music.mcgill.ca/~gary/rtaudio/index.html. You might want to consider also using that directly. Hope that helps.