How to create a new command line? - r

I have a very simple question, How to create a new command line?? my code is
barplot(Danes, col = rainbow(12), beside = T)
legend(locator(1), legend = rownames(Danes), col = rainbow(12), pch = rep(18, 12))
But when I click enter, it creates the graph but doesn't give me a new command line (<) or gave me the legend so I guess I must have messed the legend command up. how do I basically restart and keep my data and code?

Your problem is locator(1). R is waiting for you to click somewhere in the plot window (to decide where to put the legend). Alternatively, if you want to cancel the action (from ?locator):
For the usual ‘X11’ device the identification process is
terminated by pressing any mouse button other than the first. For
the ‘quartz’ device the process is terminated by pressing the
‘ESC’ key.
(it doesn't say what to do for a Windows graphics device, but I'd try ESC and other mouse buttons and maybe Ctrl-C).

Related

changing the text in a toolbar with pywinauto

I have a file selection window from an windows application I'm trying to automate.
I can change the File name box at the bottom by using
app2.window(title_re='Select a batch file') \
.File_name_Edit.set_text(selected_filename)
I have previously entered the full filepath and filename in to the lower box, however, it will no longer accept slashes in the File name box after a windows update. Hence the problem.
So the problem is the top (directory/folder name) box.
Manually I can select the box, highlight it then overtype the directory.
I cannot find a way to do this using pywinauto.
Methods attempted are:
toolbar2 = app2.window(title_re='Select a batch file') # \
# .child_window(title_re='Address', auto_id='1001')
# .child_window(title_re='Address', control_type="ToolBar", auto_id='1001')
file_path_address = toolbar2['Address band toolbarToolbar'].click_input()
file_path_address.set_text(directory_path)
# ToolbarWrapper(toolbar2).set_text(directory_path)
# ToolbarWrapper(toolbar2).click(button='All locationsSplitButton').set_text(directory_path)
# ToolbarWrapper(toolbar2)['Address:'].set_text(directory_path)
I'm using set_text as the automation must run behind a locked screen, type_keys does not work with a locked screen as type_keys is a keyboard method and Windows blocks keyboard entry when the screen is locked.
I have no access to the internals of the program being automated in order to change the original directory path and need to change it to read in from a different location.
Any assistance would be appreciated.
See below code, It runs fine with Notepad++ on Win 10
import time
from pywinauto.application import Application
app = Application().Connect(title=u'Open', class_name='#32770')
window = app.Dialog
toolbarwindow = window.Toolbar3
toolbarwindow.Click()
time.sleep(0.30)
static = window.Edit2
directory_path = "C:\Users\Desktop"
raw_directory_path = r'{}'.format(directory_path)
static.set_edit_text(text = raw_directory_path)
static.type_keys("{ENTER}")
you can use right click then edit the field
toolbar2['Address band toolbarToolbar'].click_input(button="right")
app2.PopupMenu.child_window(title="Edit address", control_type="MenuItem").click_input()
app2.child_window(title="Address", control_type="Edit").set_edit_text(directory_path)

tradingview pine script error "cannot use 'plot' in a local scope"

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input.
If the box is checked, the plot the line.
If the box is not checked do not plot the line.
This is the code I have:
notPlot = -2000
var ch382= input(true, ".382")
if ch382
plot( ch382? bottom + diff * .382: noPlot, title="fib-.236", linewidth=3, color=color.orange )
How can I write this in a proper way?
If I try to run it, I get: “cannot use 'plot' in a local scope”
Any assistance would be greatly appreciated.
ETA: I found this thread below
How to put plot statement inside if statement
but -
what I need to do is to plot if the box is checked and ~not plot~ if the box is not checked.
ETA: figured out the issue. One would use "na" (in the case of plotting) to note that the line should not be displayed - my mistake ...
var ch382 = input(true, ".382")
plot( ch382? bottom + diff * .382: na, title="fib-.382", linewidth=3, color=color.orange )

How to suppress unwanted Plot figure object information in Jupyter Notebook

I want to suppress any text output when I run Jupyter Notebook cell. Specifically I output some figures and each is accompanied by something like:
<Figure size 432x288 with 0 Axes>
I have seen that if I put a ; at the end of a line, it should suppress the output, but it is not working in my case.
The code:
for i in tqdm_notebook(range(data.shape[0])):
print('BIN:',i)
fig = plt.figure(figsize=(15,4))
plt.tight_layout()
gs = gridspec.GridSpec(2,1)
ax1 = fig.add_subplot(gs[0, 0])
ax1.plot(match[window_begin:window_end],'k')
plt.vlines(i,-np.max(match[window_begin:window_end])*0.05,np.max(match[window_begin:window_end])*1.05,'r',linewidth=4,alpha=0.2)
ax1.set_xlim(0-1,post_bin_match_median[window_begin:window_end].shape[0])
ax1.set_ylim(-np.max(match[window_begin:window_end])*0.05,np.max(match[window_begin:window_end])*1.05)
plt.tick_params(axis='y', which='both', left=True, labelleft=False)
ax1.tick_params(axis='x', which='both', bottom=False, labelbottom=False)
plt.grid()
ax2 = fig.add_subplot(gs[1, 0])
fig.subplots_adjust(hspace=0.0)
ax2.plot(gp_mjds[:],gp_data[i,:],'k')
ax2.errorbar(remain, all[i,:], yerr=all_noise[i], fmt=".k", capsize=0);
ax2.fill_between(gp[:], gp2[i,:] - np.sqrt(gp_var[i,:]), gp2[i,:] + np.sqrt(gp_var[i,:]),color="k", alpha=0.2)
ax2.set_xlim(gp[0],gp[-1])
plot_y_min = np.minimum(np.min(gp2[:,:] - np.sqrt(gp_var[:,:])),np.min(all_profile_residuals[:,:]-y_noise))
plot_y_max = np.maximum(np.max(gp2[:,:] + np.sqrt(gp_var[:,:])), np.max(all[:,:]+y_noise))
ax2.set_ylim(plot_y_min,plot_y_max)
plt.grid()
plt.show()
plt.clf()
plt.close(fig);
The semi-colon would work if the typical output from the last line of the cell is what you are trying to suppress. As succinctly summarized by #kynan here, "The reason this works is because the notebook shows the return value of the last command. By adding ; the last command is "nothing" so there is no return value to show."
However, you have a loop inside a cell generating objects.
The culprit seems to be plt.clf(). Comment out that line or remove it from your code, and it should fix it.
Plus, I'd remove plt.show() as it isn't necessary when plt.clf() is removed, and I am seeing it being in the loop causing fig = plt.figure(figsize=(15,4)) to also show output text like you posted in your issue.
(I'll add for others looking at this later, that it is important have %matplotlib inline or %matplotlib notebook at the start of the cell (or at the start of a cell somewhere above this one.))
A complete guide on how to hide or remove content in Jupyter is available from the official documentation: https://jupyterbook.org/interactive/hiding.html#
For removing the single output line, you can tweak the command lines by adding a _ = [command ] assignment as suggested in this blog: https://www.tutorialguruji.com/python/suppress-output-in-matplotlib/.
The underscore there is a throwaway variable, actually an unidentified variable "when not in interactive mode". See the official Python documentation: https://docs.python.org/3.9/reference/lexical_analysis.html#reserved-classes-of-identifiers

Shortcut to open a new line at any position of the current line in R studio script

I am using R studio for hunderd of times a day. I write many lines. I would like to jump to a new line under a current line (at any position) without going to the front or the end of line and then hit enter. Is there any shortcut to do so? any help please?
There is an official feature request for this here
Because it's a feature request, you can use a hotkey/text expander program to map Shift + Enter -> Command + Right , Enter

AutoIT get child window from a parent window

I came across a problem which looks trivial to me but I can't find a valid solution after googling for an hour.
I want to fill in a window security popup window.
This is part of a selenium test, that can run in parallel next to other tests.
So in order to be sure that my autoit script fills in the correct popup (and not form another test that is running), i want to identify this popup as a child of a parent window. Is there an easy way to do this?
The code i had so far:
$browserHandl = WinWait($parentTitle)
WinActivate($browserHandl, "")
$popUpHandl = WinWait("Windows Security")
So my fear is that WinWait will return one of all the open Windows Security popups currently open on the machine.
So:
1. Is there a way to obtain the childwindows of a parent window when i got its handle?
2. Is my fear correct that i indeed will have a race condition with multiple tests running at the same time?
input box open
input box hidden
I used a progress to hide what I needed to.
add #include
$file = GUICtrlCreateInput("", 10, 5, 350, 25)
You need 3 lines for the Marquee
Local $iProgress = GUICtrlCreateProgress(30, 10, 270, 20, $PBS_MARQUEE)
GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 1, 50)
and to make it cover the input box
and 0 to stop and remove the Marquee GUICtrlSendMsg($iProgress, $PBM_SETMARQUEE, 0, 50) ; Send the message $PBM_SETMARQUEE and wParam of 0 to stop the scrolling marquee.

Resources