Can I debug inside a for or if in julia? - julia

would you please help me? if I have a code including some loops and IFs, how can I debug inside FOR or IF, line by line.
for example
I can use shift+enter for every line. but when it is used for a For all loop will run. Is there any facility to debug inside a loop line by line?
thanks

You can run line by line in e.g. Juno by just highlighting the line, that will not run the entire loop. I'd recommend doing that.
With regards to an actual debugger, there is not currently one available for julia-1.x. But there's Rebugger.jl, it's use is quite advanced though.

Related

Hiding JupyterLab cell's output by default

I am using JupyterLab to build a bioinformatics pipeline that uses both bash and python scripts.
The first bash script results gives a lot of feedback on every step of the process. However, this feedback is not helpful (unless there was an error) and makes the document less readable.
I would like to be able to hide this cell's output by default, but also to be able to open it when necessary to troubleshoot. I know it's possible to click 3 times on the output to collapse it; I was just wondering whether there is a way to do so by default.
I tried to add the tag specified on here (https://jupyterbook.org/features/hiding.html#Hiding-outputs) to the cell, but it does not seem to work for me.
Thanks for your help.
You may just want to suppress the output using %%capture cell magic as illustrated here. Then you simply remove that magic command from the first line of the cell for times you want to see the output, such as when troubleshooting.
If you want to make it so every time you run the cell, you can later decide to review what was captured you can use the %%capture magic command more as it was meant to be used. By assigning what is captured you can also do something like what the %%bash cell magic allows with handling output streams (see here), too. As described and illustrated here using the utils object you can easily get the stdout and/or stderr as a string, see http://ipython.readthedocs.io/en/stable/api/generated/IPython.utils.capture.html.
So say you put the following at the top of you cell to assign what was captured to out:
%%capture out
You can review the stdout stream later with the following:
print(out.stdout)
Or if you just want part of it, something like print(out.stdout[1:500]). I have some fancier handling illustrated in some blocks of code here.

Compose.jl output issue

Ok recently I have been experimenting with Julia's compose.jl and have run into a somewhat confusing problem. I will run the standard code to initialize the package.
Pkg.add("Compose")
using Compose
compose(compose(context(), rectangle()), fill("tomato"))
And then run that code. Here is my problem: the code executes fine, it's the output that is strange. The typical output for this code would be a red rectangle. The output I get when this code is run is this:
Context(BoundingBox(Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),1.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,1.0)),UnitBox{Nothing,Nothing,Nothing,Nothing}(nothing,nothing,nothing,nothing,Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0)),Rotation{Point{Measure{MeasureNil,MeasureNil},Measure{MeasureNil,MeasureNil}}}(0.0,Point{Measure{MeasureNil,MeasureNil},Measure{MeasureNil,MeasureNil}}(Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.5,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.5))),nothing,ListNode{ComposeNode}(Property{FillPrimitive}([FillPrimitive(AlphaColorValue{RGB{Float64},Float64}(RGB{Float64}(1.0,0.38823529411764707,0.2784313725490196),1.0))]),ListNode{ComposeNode}(Form{RectanglePrimitive{P<:Point{XM<:Measure{S,T},YM<:Measure{S,T}},M1<:Measure{S,T},M2<:Measure{S,T}}}(RectanglePrimitive[RectanglePrimitive{Point{Measure{MeasureNil,MeasureNil},Measure{MeasureNil,MeasureNil}},Measure{MeasureNil,MeasureNil},Measure{MeasureNil,MeasureNil}}(Point{Measure{MeasureNil,MeasureNil},Measure{MeasureNil,MeasureNil}}(Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,0.0)),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),1.0,0.0),Measure{MeasureNil,MeasureNil}(0.0,MeasureNil(),MeasureNil(),0.0,1.0))]),ListNull{ComposeNode}())),0,false,false,false,false,nothing,nothing,0.0)
a rather lengthy piece of text that doesn't show the shape... I am wondering if this is an error or if I am just doing something wrong. Does anyone know how to make this output what it should be?
One possibility to open an image through REPL would be through TerminalExtensions.jl. But generally I believe you have to write the image to a file and then open it. To save the file use this,
julia>draw(PNG("test.png", 10inch, 10inch), compose(compose(context(), rectangle()), fill("tomato")))

Execute a block of code but show all results in Julia/Juno

I have Julia code edited in Juno, which contains a very simple code block with a calculation at each line. When I select it all and execute it, only the result for the last line is displayed:
I'd like to execute the block, but have the results for each line, like this (image obtained executing line by line):
Is it possible (via some shortcut or option)?
There's no way to do this yet, although it's something we'd like to see in future. I opened an issue to track the feature.
One thing that might help is the Shift-Enter command, which is the same as C-Enter but skips to the next code block. If you repeatedly Shift-Enter from the beginning of that block of code you'll get all of the results very quickly, if not quite instantaneously.

Hide and show comments

I'm writing all my scripts on .R file using R for mac. It is convenient to me because there are colors to highlight the type of commands.
I have a many comments following the # symbol that are useful when I forget about the meaning of my script but they tend to blur my script so that it gets harder to find a given command line.
Is there a way to hide and show these comments ? (Using the programm I'm currently using or another one). What would you suggest as the best program to write R script ?
Thanks a lot !
RStudio supports code folding. You can standardize your comment blocks so that they are recognized as code blocks.
For example, enter this into your RStudio editor
#=======================================================
# this is a comment block
# more comments here
# comments upon comments
and then press Alt+L to fold, and Alt+Shift+L to unfold.
Try RStudio for mac. One of the greatest code writing environment for R there is.
You can also try Emacs, which is more like old-fashioned command line editor. You can find a good guide here.

Is there any way in Linux to show what's going on about the freezing code on the R session?

I am running a set of selected code on R. Like
source("/tmp/r-plugin-honli/Rsource-2704-quantmod.R")
There is no output. Only the prompt '>' flickered there.
I use 'killall' to kill the R session. But I don't know where is wrong on the code. Because R did not give any output. How could I know what's going on about the code.
I'd try two things:
Run the code interactively. As in, open the Rsource-2704 file and run its lines one by one.
If that doesn't replicate the problem or is not possible, you can take Joshua Ulrich's suggestion or use:
R CMD BATCH --vanilla Rsource-2704-quantmod.R out.log
Which will run the code in a batch mode and output the usual console lines to a file called out.log (you can name it whatever you like).
Instead of using print statements, you could also take a look at the browser() command. This drops you into an interactive session at the point where the command is put. This works particularly well when trying to figure out what is happening inside a function, although I don't know if your script contains them.

Resources