This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Function to Clear the Console in R
Is there a way to invoke the Clear Console (Ctrl+L) menu command programmatically?
I use a function for doing that, and actually have put it in {R directory}\etc\Rprofile.site so that it will always be available for use.
cls <- function() {
require(rcom)
wsh <- comCreateObject("Wscript.Shell")
comInvoke(wsh, "SendKeys", "\014")
invisible(wsh)
}
cls()
To clear the console give
cls()
P.S. The function doesn't work the first time it's called and that's why I invoke the function immediately after declaring it in Rprofile.site. As I recall, you may be asked to install some program, in order for this to work.
Create this function:
cls <- function() cat(rep("\n",100))
Then call it:
cls()
Works with:
Windows
Linux
Mac
I might be missing the point dramatically, but is simple system("clear") an easier approach? Of course, it can only be applied on Linux/Unix environments...
Related
This question already has answers here:
Pretty-print for shell script
(4 answers)
Closed 7 years ago.
Talking about good coding practices. My code is getting bigger and bigger and I want to check if all my "if", and "for" loops are properly written.
I think the proper word for that is indentation (thanks #tgo).
So I have this:
if(cond1 = cond2)
if(cond3=cond4)
bla
fi
fi
but I want the following:
if(cond1 = cond2)
if(cond3=cond4)
bla
fi
fi
But for instance using Sublimetext I cannot see it like this. So repeating the question, is there any tool, software or something that can help me with this?
update: Sublime text has an option for this. (Edit-> line-> Indent) I couldn't add this to the answer.
I use vim for all my code editting (and I write a lot of bash scripts) and it has smart indenting that defaults to normal, ok stuff for all the languages I use. If you have smart indenting turned on and copy and paste code from your first block into vim (properly set up with filetype=sh), it'll turn out like your second block.
So.. I just downloaded Xojo 2014 for OS X, and up to this point have found it a pretty simple and effective development environment.
However, I've been trying to make a function or sub routine for 45 minutes. Every time I try following tutorials or the Xojo documentation I get the following error:
I've followed (even though I could be missing something) the directions here: http://docs.xojo.com/index.php/Function
Even though there is no full example in the documentation (bad development environment).
Also, in the screen shot is showing a sample function I copied and pasted off Xojo forums and is supposed to work. I'm not a programming newb per say, but more an Xojo newb. I've also had experiences with silly bugs in RealStudio in the past.
Can someone maybe point out what I could be missing?
You cannot use the Function, Sub, End Function, or End Sub lines in the method editor. Doing so will cause a syntax error because method declarations are automatically added by the IDE based on the values you enter into the method editor's name, parameters, and return type fields.
e.g.
as said,
Function, Sub, End Function, or End Sub is done for you,
you can do 'exit sub' if nothing need to be returned, else just return a proper value
like some events need a true or false, so if you need the exit the function, just return false
You cannot add inline functions within your Xojo code. You add methods to your project items these ways:
Insert->Method
"+" button on editor toolbar, then Method
Insert button on main toolbar, then Method
Option-Command-M (on OS X)
This question already has an answer here:
How to unhide an overriden function?
(1 answer)
Closed 9 years ago.
On my Matlab path there's a custom zeros function. I want to store a handle to the built-in zeros in a variable. How can I do that?
Thought about #(varargin)builtin('zeros',varargin{:}), but this would probably slow down the operation due to the string comparison.
Also, I've noticed that it's possible to refer to diag as #numel\diag, but this doesn't seem to work with other built-in functions (zeros in particular).
Suggestion #1
% At the beginning of your script:
rmpath('C:\the\folder\containing\the\custom\zeros');
builtInZeros = #zeros;
addpath('C:\the\folder\containing\the\custom\zeros');
% Calling the custom zeros later:
a = zeros(10, 20);
% Calling the built-in zeros:
b = builtInZeros(10, 20);
Suggestion #2
Put these three lines into your startup file:
rmpath('C:\the\folder\containing\the\custom\zeros');
builtInZeros = #zeros;
addpath('C:\the\folder\containing\the\custom\zeros');
Suggestion #3
It's definitely a dangerous idea to reuse the name of a built-in function. It ruins the readability of your scripts, making them much more difficult to maintain. So if you have control over the custom zeros function, then rename it to something else. Use a name which describes how the custom version is different from the built-in one (for example, call it fastZeros if it's faster).
Well, this doesn't give you an exact answer to your question, but it could solve the problem:
I think this seems to be a good solution:
matlabcentral: How to call a shadowed function
Withn the last post:
Just stumbled upon this problem and found the following solution: For
example, I have matlab svmtrain shadowed by libsvm toolbox:
which svmtrain -all
C:\Projects\Ichilov\Misc\MVPA\libsvm-mat-3.0-1\svmtrain.mexw64
C:\Program Files\MATLAB\R2009b\toolbox\bioinfo\biolearning\svmtrain.m
% Shadowed
But I can access the original function by using str2func:
org_svmtrain = str2func([matlabroot '\toolbox\bioinfo\biolearning\svmtrain'])
and then simply calling:
org_svmtrain(training, groupnames)
I'm attempting to make a gui application in F# that uses a dialog box to open a file
however whenever I try to use it, the program crashes with that exception
here's my code:
let openAndDrawChart e =
let dlg = new OpenFileDialog(Filter="CSV Files|*.csv")
if dlg.ShowDialog() = DialogResult.OK then // code crashes here
let pieChart = drawChart dlg.FileName
boxChart.Image <- pieChart
btnSave.Enabled <- true
If I try to put a try with block around it, the program just crashes after the "with" keyword
Also, if I replace the code following then with a () then the program still crashes, the code never gets past the if ... then statement
So does anyone here know what I'm doing wrong, and how I can fix it?
I just want to point out that I'm more accustomed to making gui applications in C#, so trying to do it in F# is new to me
Here's the exception's exact words:
OK so, this is a little bit embarrassing but
apparently the program doesn't play well with an entry point...
At the bottom of my code I had this:
[<EntryPoint>]
let main args =
0
Which I just removed...
I didn't think it mattered much since the program executed the code above the entry point anyway
But apparently it was was enough to mess up the whole thing!
Sorry for the inconvenience, though it might be a good thing to leave this here for future reference
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
General suggestions for debugging R?
I've encountered an error when calling a function from an R package. Briefly,
> library(treemap)
> ...
> tmPlot(X,index=c("r1","r2","r3","r4"),vSize="size")
Error in if (maxI == 1) { : missing value where TRUE/FALSE needed
This SO question gives more details.
I examined the source code of tmPlot by typing tmPlot at the R prompt, but the line that fails doesn't appear in the function. Which means, I assume, that it's failing in some function called by tmPlot.
What's the best way to track this down? For example, can I generate a stack trace somehow? Is there an interactive debugger that will allow me to step through and see where the error happens?
traceback will print the call stack.
traceback()
Also, have a look at the on-line help for the debug function. Although I have seen better interactive debuggers, there is some basic functionality provided by debug(), debugonce() and undebug()
?base::debug