I often find myself using ctrl + enter to run something in r-studio. I often find that I would like to be able to wrap whatever I am putting into ctrl + enter in the str() function.
This is particularly the case when I am piping lots of dplyr verbs together. Mutating new variables and joining dataframes etc. Sometimes halfway through the set of piped commands I need to check what the name of a variable in a dataframe that i have created is called so that i can access it via the next pipe. This usually means that i have to:
highlight the text up to the last relevant pipe
hit ctrl + enter
press the up arrow
add a bracket to the end of the pasted text
Press home
navigate via the arrows to the first line of the pasted text
type: str(
This is extremely laborious and I find myself doing it often. Is there a shorter way that I am not aware of? Otherwise is there a workflow process people use to get around this?
Ideally there would be a modified ctrl + enter shortcut that would wrap whatever is highlighted in str() and output the result to the terminal.
Related
I have a text like this:
"Hello how
are you" %>% word(-1)
I get an error if I perform this because I pressed Enter after how. How do I remove the hidden line break so as to perform my code on the text?
Ok, I found the exact mechanism to make this reproducible.
This happens under 2 conditions that are my default way to process code in R.
In a chunk
You don't execute the chunk, but the line pressing ENTER + CTRL
Solution: execute the chunk instead.
Main question
I would like to add powerline characters at the start and at the end of the selected completion, like this:
Started the completion menu by inserting c and pressing the TAB key.
Moved right in the completion menu by pressing the right arrow key.
Moved down in the completion menu by pressing the down arrow key.
Is there any way to make zsh look/behave like in the pictures?
Note
Added powerline triangle + blank character at the beginning and blank character + powerline triangle at the end should somehow be accounted when columns are created to keep the alignment correct.
Bonus
Add 2 blanks at the beginning of every completion in the list, so that when the completion is selected it doesn't look like the text was moved to the right.
( This issue can be seen by comparing the completion with and without the selection. )
Alternative question
In case that previously explained behavior is impossible to get without changing the zsh source code, is it at least possible to add powerline triangle only at the end of the selected completion?
My unsuccessful attempts
I have tried using the lc, rc, and ec variables in the list-colors style but that didn't help:
Completion list was badly aligned and it created all kinds of visual problems.
Symbols were inserted in all elements of the completion list, not just the selected one.
I have also tried using the ma variable, but I couldn't properly insert a character at the beginning:
The variable expects only a number that represents a color and it is probably wrapped in some escape sequences, so the output did not look as expected.
This works for me.
zstyle ":completion:*:default" list-colors ${(s.:.)LS_COLORS} "ma=48;5;153;1"
Uses my LS_COLORS and then ma sets the background of my selection to bold and color 153 from https://jonasjacek.github.io/colors/.
Found from https://www.zsh.org/mla/users/2010/msg00811.html
I have entered in code to plot a graph, but when I press Enter to execute the graph, it does not plot the graph. Rather, + symbols appear every time I press Enter to execute the command and plot the code.
Now there is a long column of + symbols in my R consoles.
Why is this happening and what can I do to prevent this from happening?
The prompt has + because it signifies that the prompt is expecting more from the line of code, a sort of continuation. This may be because you forgot to close something so the prompt expects the closing side. For example, say you forgot to close a string like so:
> "
+
+
Here, I entered a double-quote into the prompt and kept on pressing Enter. There is a missing double-quote to tell the prompt I've ended the string literal, so the prompt expects another double-quote. Once you enter the double quote the prompt will stop expecting it. For example:
> "
+
+ "
[1] "\n\n"
This is standard on all command prompts, to expect more code if something isn't ended properly, like the string literal above. Check your code to make sure you've closed all opening quotes, symbols, etc, so the prompt doesn't expect it and your code executes correctly.
The ways of exiting the prompt when this happens are:
Esc on RGui and RStudio
Ctrl-C on Terminals and Command Prompts
This could happen if you used space in the middle of an object name, eg. Column names. R doesn't allow space in between " ".
What are the equivalent ways to calling the beginning (or ending) of a data set in Octave / MATLAB?
These are incredibly useful functions to avoid printing out the entire dataset on the console, and get an idea of the headings and type of data.
It would be great to also have an equivalent for str() along the same lines...
There is no built-in but you can easily grab the first N rows or the last M rows.
A = rand(10000, 2);
% First 10 rows
A(1:10, :)
% Last 10 columns
A((end-9):end,:)
The same will work if you are using a table to store your data.
t = table(rand(10000,1), rand(10000,1));
t(1:10,:)
t((end-9):end,:)
Or a dataset
d = dataset(rand(10000,1), rand(10000,1))
d(1:10,:)
d((end-9):end,:)
You could easily create the following head() and tail() anonymous functions which you could use to do this easily.
tail = #(data)disp(data(max(size(data, 1)-9, 1):end,:));
head = #(data)disp(data(1:min(10, size(data,1)),:));
And use them like a normal function
head(d)
Variables editor can be useful for quickly inspecting your data. There's also a handy keyboard shortcut to open your variable in the editor - select the variable name (either in editor or in command window) and press ctrl+D. It also displays structure arrays quite nicely - often that's much easier than inspecting through command window.
For example, I have many HTML tabs to style, they use different classes, and will have different backgrounds. Background images files have names corresponding to class names.
The way I found to do it is yank:
.tab.home {
background: ...home.jpg...
}
then paste, then :s/home/about.
This is to be repeated for a few times. I found that & can be used to repeat last substitute, but only for the same target string. What is the quickest way to repeat a substitute with different target string?
Alternatively, probably there are more efficient ways to do such a thing?
I had a quick play with some vim macro magic and came up with the following idea... I apologise for the length. I thought it best to explain the steps..
First, place the text block you want to repeat into a register (I picked register z), so with the cursor at the beginning of the .tab line I pressed "z3Y (select reg z and yank 3 lines).
Then I entered the series of VIM commands I wanted into the buffer as )"zp:.,%s/home/. (Just press i and type the commands)
This translate to;
) go the end of the current '{}' block,
"zp paste a copy of the text in register z,
.,%s/home/ which has two tricks.
The .,% ensures the substitution applies to everything from the start of the .tab to the end of the closing }, and,
The command is incomplete (ie, does not have a at the end), so vim will prompt me to complete the command.
Note that while %s/// will perform a substitution across every line of the file, it is important to realise that % is an alias for range 1,$. Using 1,% as a range, causes the % to be used as the 'jump to matching parenthesis' operator, resulting in a range from the current line to the end of the % match. (which in this example, is the closing brace in the block)
Then, after placing the cursor on the ) at the beginning of the line, I typed "qy$ which means yank all characters to the end of the line into register q.
This is important, because simply yanking the line with Y will include a carriage return in the register, and will cause the macro to fail.
I then executed the content of register q with #q and I was prompted to complete the s/home/ on the command line.
After typing the replacement text and pressing enter, the pasted block (from register z) appeared in the buffer with the substitutions already applied.
At this point you can repeat the last #qby simple typing ##. You don't even need to move the cursor down to the end of the block because the ) at the start of the macro does that for you.
This effectively reduces the process of yanking the original text, inserting it, and executing two manual replace commands into a simple ##.
You can safely delete the macro string from your edit buffer when done.
This is incredibly vim-ish, and might waste a bit of time getting it right, but it could save you even more when you do.
Vim macro's might be the trick you are looking for.
From the manual, I found :s//new-replacement. Seemed to be too much typing.
Looking for a better answer.