jpeg() Functionality - R Markdown - r-markdown

I have two questions actually.
I am currently trying to use jpeg() with RMarkdown. It used to work quite well but stopped working and have no idea why. </p>
a. Here is my code:
attach(Hippocampus)
jpeg("Pictures_OnePlot.jpeg", width = 5, height = 3.5, units = "in", res = 600)
plot(Months_as_Taxi_Driver, Anterior_Hippocampus_Volume_mm3,
main = bold("Volume /")~ bold(mm^3) ~ bold("vs Months as a Taxi Driver"),
cex.main = 1.25,
cex.lab = 1,
xlab = "Anterior Hippocampus Volume" ~ (mm^3),
ylab = "Months as Taxi Driver")
graphics.off()
Code
Hippocampus Data
Moreover, now when I try running the code or knitting my file, it does not work at all.
Once the above gets fixed, how do I save this file into a different folder or into a subfolder within the same folder? Before, it would just save it in the same folder as the R-Markdown folder, but I'd like it to go into a sub-folder.
Thanks for the help, everyone. :)
I tried using dev.off() at the end instead and tried Googling with no avail. There was a similar thread though they used x11(), which doesn't work with R (and I am not even sure what x11() is, but that is a different story).
I know how to do the above via ggsave() when I use ggplot, but I'd like to know this method too (especially when using plot().
Thanks again!

Related

How do I change terminal display? Visual Code on Mac

When Running my code I really only want to display the code I'm working on. I don't want to display what seems to be the folder address. Is there a way to not display that?
I mean when im running my code. I want to see the answer to my code only so to just display
28
.... not the folder name desktop/cpp etc etc
I noticed you were having some trouble with VS-Code.
Here's a good list of commands which can complete your task.
I noticed you stated that you were on a Mac as well, so more than likely the CTRL + option won't be necessary; try the " ⌘ + " instead!
To remove / hide the folder explorer window, simply hit "⌘ + b"
To remove / hide the terminal as well, try using "⌘ + `"
Edit:
I noticed you were also having some issues with the output of your code. The "addresses" to your output are symbols that ( usually ) address incorrect operations.
Try doing something like this when writing out your function:
printf( "i%\n" ); // <- Adding a newline to the operation deducts the symbol.
I hope this helps-

GDI Print API StartDoc function is giving inconsistent results

In my application a user can have multiple documents open and print all documents to PDF's using a "Microsoft print to pdf" option when they are prompted at the print dialog window, after which they choose the destination folder. Now what happens is that if there are 30 documents selected for print, an inconsistent amount are successfully printed to pdf in the desired folder each time it is run. Sometimes all are successful and other times not. I found that files with unicode character names like this "敥敥敥敥敥敥敥敥" where being created in the same directory as the file of code that contains this print to pdf process. I can rename these files with a ".pdf" extension and they are working pdf documents.
Here is the part of code concerned:
DOCINFO docInfo;
memset(&docInfo, 0, sizeof(docInfo));
docInfo.cbSize = sizeof(docInfo);
docInfo.lpszDocName = csPlanoName;
docInfo.lpszOutput = csOutputDir + csPlanoName + csExtension;
if(dc.StartDoc(&docInfo) > 0) {
//printing process continues
}
I found that by stepping through the code, the StartDoc function call would change docInfo.lpszOutput to the same unicode characters "敥敥敥敥敥敥敥敥". This would not happen all the time, and does not happen with specific files when testing. One test a document will print to pdf successfully, another test with the same document and it will create the file with the name "敥敥敥敥敥敥敥敥".
Any help with this would be greatly appreciated.
Regards,
Chris
What are csPlanoName csOutputDir? docInfo.lpszDocName and docInfo.lpszOutput must be pointers to null-terminated strings and since you are using csOutputDir + csPlanoName + csExtension that won't work with regular pointers something else might be happening here. Make sure that result of csOutputDir + csPlanoName + csExtension is not getting implicitly cast to pointer and then going out of scope.
using a string conversion macro seems to have solved my problem, successfully tested outcome 10+ times.
CString csFullpath = csOutputDir + csPlanoName + csExtension;
docInfo.lpszOutput = CT2W(csFullpath);

Passing a string variable between my c++ code to matlab

I am new to matlab, and coding is not my job, I just use it for some side projects. So I don't really know what I am talking about, and I hope you'll understand that :)
So I installed matlab on my computer and would like to use its libraries to plot some very simple graphs during the execution of my code (histograms, scatter plots, whatever). Plotting those graphs is not the first purpose of my code, I just find that easier to plot them during the execution rather than exporting them as a CSV file, and then plotting manually through excel.
Question: I managed to make visual C++ "communicate" with matlab. I am passing some data using arrays, but I'd also like to pass a string (a path such as "C:\test\") as I'd like to automatically save those graphs once generated into a precise directory. I haven't found any way of doing it so far.
Here is a bit of my c++ code, which is really simple:
Engine *ep;
ep = engOpen(NULL);
double *ArrayOne;
double *ArrayTwo;
const int Asize = Area.size();
ArrayOne = new double[Asize];
ArrayTwo = new double[Asize];
for (int i = 0; i <= Area.size() - 1; i++) {
ArrayOne[i] = Area[i][1];
ArrayTwo[i] = Area[i][2]
}
mxArray* ONE = mxCreateDoubleMatrix(Asize, 1, mxREAL);
memcpy((void*)mxGetPr(ONE), (void*)ArrayOne, sizeof(double)*Asize);
engPutVariable(ep, "one", ONE);
mxArray* TWO = mxCreateDoubleMatrix(Asize, 1, mxREAL);
memcpy((void*)mxGetPr(TWO), (void*)ArrayTwo, sizeof(double)*Asize);
engPutVariable(ep, "two", TWO);
engEvalString(ep, "plottest");
delete[]ArrayOne;
delete[]ArrayTwo;
engClose(ep);
And the file Plottest.m:
h1= histogram(one);
h1.EdgeColor = 'black';
h1.FaceColor = 'white';
hold on;
h2 = histogram(two);
h2.EdgeColor = 'blue';
h2.FaceColor = [0.5 0.5 0.5];
alpha(h1,.5);
alpha(h2,.8);
saveas(gcf,'C:\PhD\SVG2GMSH\SVG\test.png');
How can I replace my hard coded path into my m file ("C:\PhD\SVG2GMSH\SVG\test.png") by a more elegant variable that would contain it ?
Thank you for your help. Also, let me know if you have any other suggestions in order to make my code look/work better :)
Flo
I don't see what benefit a variable would bring when you'd only need to update the value of the variable anyway.
Your best bet is to use a relative path: saveas(gcf, 'test.png') then the file is taken from the current working directory. The documentation doesn't actually outright state this, but it's basically how computers work, so… give it a go!

weka: how to generate libsvm training parameter

I am running libsvm through weka. Its output accuracy looks good to me, so I am planning to write a svm model by myself. However, weka didn't generate any training parameter, such as number of support vector. Therefore i cannot do anything. Searching the web, i found somebody said it would generate some parameters like the following:
optimization finished, #iter = 27
nu = 0.058475864943863545
obj = -1.871013102744184, rho = -0.19357337828800944
nSV = 9, nBSV = 0 `enter code here`
Total nSV = 9
but how come i didn't see any of them? any step that i missed? please help me. Thanks a lot.
Weka writes the output you mentioned to stderr.
So if you have started weka.sh or weka.bat from a terminal (or "command window" if you are on Windows), you should see that output appear in your terminal window after clicking "classify"
If you want to have access to this information via scripts, you can
redirect the output to a file and read in that file.
Here is how to edit the startup file weka.sh / weka.bat.
Edit this line (it is probably the last line) in order to write log info to a file instead of the terminal window:
java -cp $CP -Xmx8092m weka.gui.GUIChooser 2>>/opt/weka-stable/weka.log &
You can also add a properties file to your home directory to add more fine-grained behaviour.
https://weka.wikispaces.com/Properties+file
(You probably can also access information via the Weka Java API somehow, but you did not ask for that)

Identifying a Programming Language

So I have a software program that for reasons that are beyond this post, I will not include but to put it simply, I'd like to "MOD" the original software. The program is launched from a Windows Application named ViaNet.exe with accompanying DLL files such as ViaNetDll.dll. The Application is given an argument such as ./Statup.cat. There is also a WatchDog process that uses the argument ./App.cat instead of the former.
I was able to locate a log file buried in my Windows/Temp folder for the ViaNet.exe Application. Looking at the log it identifies files such as:
./Utility/base32.atc:_Encode32 line 67
./Utilities.atc:MemFun_:Invoke line 347
./Utilities.atc:_ForEachProperty line 380
./Cluster/ClusterManager.atc:ClusterManager:GetClusterUpdates line 1286
./Cluster/ClusterManager.atc:ClusterManager:StopSync line 505
./Cluster/ClusterManager.atc:ConfigSynchronizer:Update line 1824
Going to those file locations reveal files by those names, but not ending with .atc but instead .cat. The log also indicates some sort of Class, Method and Line # but .cat files are in binary form.
Searching the program folder for any files with the extension .atc reveals three -- What I can assume are uncompiled .cat files -- files. Low and behold, once opened it's obviously some sort of source code -- with copyright headers, lol.
global ConfigFolder, WriteConfigFile, App, ReadConfigFile, CreateAssocArray;
local mgrs = null;
local email = CreateAssocArray( null);
local publicConfig = ReadConfigFile( App.configPath + "\\publicConfig.dat" );
if ( publicConfig != null )
{
mgrs = publicConfig.cluster.shared.clusterGroup[1].managers[1];
local emailInfo = publicConfig.cluster.shared.emailServer;
if (emailInfo != null)
{
if (emailInfo.serverName != "")
{
email.serverName = emailInfo.serverName;
}
if (emailInfo.serverEmailAddress != "")
{
email.serverEmailAddress = emailInfo.serverEmailAddress;
}
if (emailInfo.adminEmailAddress != null)
{
email.adminEmailAddress = emailInfo.adminEmailAddress;
}
}
}
if (mgrs != null)
{
WriteConfigFile( ConfigFolder + "ZoneInfo.dat", mgrs);
}
WriteConfigFile( ConfigFolder + "EmailInfo.dat", email);
So to end this as simply as possible, I'm trying to find out two things. #1 What Programming Language is this? and #2 Can the .cat be decompiled back to .atc. files? -- and vice versa. Looking at the log it would appear that the Application is decoding/decompiling the .cat files already to interpret them verses running them as bytecode/natively. Searching for .atc on Google results in AutoCAD. But looking at the results, shows it to be some sort of palette files, nothing source code related.
It would seem to me that if I can program in this unknown language, let alone, decompile the existing stuff, I might get lucky with modding the software. Thanks in advance for any help and I really really hope someone has an answer for me.
EDIT
So huge news people, I've made quite an interesting discovery. I downloaded a patch from the vendor, it contained a batch file that was executing ViaNet.exe Execute [Patch Script].atc. I quickly discovered that you can use Execute to run both .atc and .cat files equally, same as with no argument. Once knowing this I assumed that there must be various arguments you can try, well after a random stroke of luck, there is one. That being Compile [Script].atc. This argument will compile also any .atc file to .cat. I've compiled the above script for comparison: http://pastebin.com/rg2YM8Q9
So I guess the goal now is to determine if it's possible to decompile said script. So I took a step further and was successful at obtaining C++ pseudo code from the ViaNet.exe and ViaNetDll.dll binaries, this has shed tons of understanding on the proprietary language and it's API they use. From what I can tell each execution is decompiled first then ran thru the interpreter. They also have nicknamed their language ATCL, still no idea what it stands for. While searching the API, I found several debug methods with names like ExecuteFile, ExecuteString, CompileFile, CompileString, InspectFunction and finally DumpObjCode. With the DumpObjCode method I'm able to perform some sort of dump of script files. Dump file for above script: http://pastebin.com/PuCCVMPf
I hope someone can help me find a pattern with the progress I made. I'm trying my best to go over the pseudo code but I don't know C++, so I'm having a really hard time understanding the code. I've tried to seperate what I can identify as being the compile script subroutines but I'm not certain: http://pastebin.com/pwfFCDQa
If someone can give me an idea of what this code snippet is doing and if it looks like I'm on the right path, I'd appreciate it. Thank you in advanced.