# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=508

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 509

---

## [Julia 1.7 saving and restoring RNG state](https://discourse.julialang.org/t/julia-1-7-saving-and-restoring-rng-state/73037)

<div class="topic-metadata">

**Author:** [@crinders](https://discourse.julialang.org/u/crinders)\
**Replies:** 3\
**Last updated:** [December 13, 2021, 9:09pm UTC](https://discourse.julialang.org/t/julia-1-7-saving-and-restoring-rng-state/73037 "2021-12-13T21:09:38Z")

</div>

Previously I checkpointed the RNG in a Julia session using multiple threads (40) with using JLD2 using Random jldopen(Filename,'w') do F F\["RNG"\] = Random.default\_rng()\` end and restored with using JLD2 using Rando…

---

## [Rotating plot around line in Makie](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 7\
**Last updated:** [December 13, 2021, 7:24pm UTC](https://discourse.julialang.org/t/rotating-plot-around-line-in-makie/73036 "2021-12-13T19:24:48Z")

</div>

Hey amazing Makie people! I would like to rotate a heatmap around a given line in a 3d scene. So far rotate!(plt, qrotation(Vec3(\[0, 1, 0\]), pi)) works great but I can only rotate against the x,y,z axis. How can I rota…

---

## [How to get stacktrace and line numbers after jl\_exception\_occurred?](https://discourse.julialang.org/t/how-to-get-stacktrace-and-line-numbers-after-jl-exception-occurred/73031)

<div class="topic-metadata">

**Author:** [@RobertN](https://discourse.julialang.org/u/RobertN)\
**Replies:** 0\
**Last updated:** [December 13, 2021, 4:57pm UTC](https://discourse.julialang.org/t/how-to-get-stacktrace-and-line-numbers-after-jl-exception-occurred/73031 "2021-12-13T16:57:57Z")

</div>

I’m loading a string from a file and passing it to jl\_eval\_string. When there is an error in the file I can tell because jl\_exception\_occured() returns non-null. But how do I get a stack trace with line numbers from that…

---

## [Why are MAT files created by Julia significantly larger than those created by Matlab?](https://discourse.julialang.org/t/why-are-mat-files-created-by-julia-significantly-larger-than-those-created-by-matlab/69793)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 15\
**Last updated:** [December 13, 2021, 3:03pm UTC](https://discourse.julialang.org/t/why-are-mat-files-created-by-julia-significantly-larger-than-those-created-by-matlab/69793 "2021-12-13T15:03:33Z")

</div>

This is how I created my MAT file using MAT F1 = matopen("test.mat", "w"); write(F1, "x", B\[:,1\]); write(F1, "y", B\[:,2\]); write(F1, "f", B\[:,3\]); close(F1) It is 898MB. If I open it within Matlab and then save('te…

---

## [Dataframes: Split combined result to different columns](https://discourse.julialang.org/t/dataframes-split-combined-result-to-different-columns/73023)

<div class="topic-metadata">

**Author:** [@TBuConst](https://discourse.julialang.org/u/TBuConst)\
**Replies:** 3\
**Last updated:** [December 13, 2021, 1:58pm UTC](https://discourse.julialang.org/t/dataframes-split-combined-result-to-different-columns/73023 "2021-12-13T13:58:40Z")

</div>

Hello everyone, I’m pretty new to Julia and struggle with a data wrangling problem. Say, I’ve got the following dataframe: using DataFrames df = DataFrame(ID = \[1,1,1,2,2,2,3,3\], OP = \[:X,:X,:Y,:X,:Y,:Y,…

---

## [Problems with StatsPlots in VSCode](https://discourse.julialang.org/t/problems-with-statsplots-in-vscode/73011)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 1\
**Last updated:** [December 13, 2021, 11:37am UTC](https://discourse.julialang.org/t/problems-with-statsplots-in-vscode/73011 "2021-12-13T11:37:27Z")

</div>

Hi all, I am wondering where I should report the following problem. In the MWE below, plots will not display in VSCode. I receive the following warning: ┌ Warning: \_display is not defined for this backend. └ @ Plots ~…

---

## [List functions that are not type stable?](https://discourse.julialang.org/t/list-functions-that-are-not-type-stable/72817)

<div class="topic-metadata">

**Author:** [@touste](https://discourse.julialang.org/u/touste)\
**Replies:** 7\
**Last updated:** [December 13, 2021, 10:53am UTC](https://discourse.julialang.org/t/list-functions-that-are-not-type-stable/72817 "2021-12-13T10:53:16Z")

</div>

Hi all, Is there a quick way to list functions that are not type stable during execution in a given module? I’m aware of the @code\_warntype macro, or the Cthulu package, but it can be quite cumbersome to descend into al…

---

## [Why is this code wrong?](https://discourse.julialang.org/t/why-is-this-code-wrong/72928)

<div class="topic-metadata">

**Author:** [@biglari](https://discourse.julialang.org/u/biglari)\
**Replies:** 15\
**Last updated:** [December 13, 2021, 10:29am UTC](https://discourse.julialang.org/t/why-is-this-code-wrong/72928 "2021-12-13T10:29:11Z")

</div>

using NearestNeighbors using SparseArrays using LinearAlgebra radius=.03 box=\[0,1,0,1\] ninit= 100 dotmax=1000 xx=range(0,stop=1,length=ninit) yy=1e-4.\*rand(1,ninit) X=vcat(xx\[:\]‘,yy\[:\]’) pdp = X’ pdp\_end = nin…

---

## [MethodError: no method matching -(::LinearAlgebra](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477)

<div class="topic-metadata">

**Author:** [@kip0d](https://discourse.julialang.org/u/kip0d)\
**Replies:** 4\
**Last updated:** [December 13, 2021, 10:02am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477 "2021-12-13T10:02:32Z")

</div>

Can you explain please what is wrong with my code? idxWindow = (-floor((N-1)/2):floor(N/2))' for indm = 1:M FD = distvec\_samp\[indm\] if FD .\> 0 IntegerD = floor(FD) FDGal = FD - IntegerD h…

---

## [Installing own package with dependency](https://discourse.julialang.org/t/installing-own-package-with-dependency/73010)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 10\
**Last updated:** [December 13, 2021, 9:42am UTC](https://discourse.julialang.org/t/installing-own-package-with-dependency/73010 "2021-12-13T09:42:02Z")

</div>

Hi, I have written a package Lithe (which I may unfortunately not share…). I have a GIT clone of it on my PC. Part of its Project.toml reads name = "Lithe" ...version = "0.1.0" \[deps\] ... Espy = "1729f5b0-844e-4123-…

---

## [Plotly() legend moving](https://discourse.julialang.org/t/plotly-legend-moving/73008)

<div class="topic-metadata">

**Author:** [@jekyllstein](https://discourse.julialang.org/u/jekyllstein)\
**Replies:** 0\
**Last updated:** [December 13, 2021, 6:04am UTC](https://discourse.julialang.org/t/plotly-legend-moving/73008 "2021-12-13T06:04:07Z")

</div>

I was trying to use commands like legend = :bottom to reposition the legend in plotly plots but having no luck. Seems like this is an unresolved issue on github. Is there some kind of workaround to position the legend ma…

---

## [LoadError: UndefVarError: @params not defined](https://discourse.julialang.org/t/loaderror-undefvarerror-params-not-defined/73005)

<div class="topic-metadata">

**Author:** [@n90](https://discourse.julialang.org/u/n90)\
**Replies:** 0\
**Last updated:** [December 13, 2021, 4:36am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-params-not-defined/73005 "2021-12-13T04:36:24Z")

</div>

In a legacy code am working on @params(:JSON\_PAYLOAD) is used to get some of the request payload. I have updated Julia to version 1.7 and and Genie version is 4.5.0. Why is @params not defined error coming? Is this a ver…

---

## [Struct wrapping NamedTuple is not \`isbits\` (depending on how it is defined)](https://discourse.julialang.org/t/struct-wrapping-namedtuple-is-not-isbits-depending-on-how-it-is-defined/72965)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 8\
**Last updated:** [December 12, 2021, 11:10pm UTC](https://discourse.julialang.org/t/struct-wrapping-namedtuple-is-not-isbits-depending-on-how-it-is-defined/72965 "2021-12-12T23:10:38Z")

</div>

I am wrapping NamedTuple to define some new/different behaviour without committing type piracy and ran into the following problem: struct Wrapper{SYMS, TT} x::NamedTuple{SYMS, TT} end randnt() = Wrapper((a = randn(),…

---

## [Bug in prevpow I guess](https://discourse.julialang.org/t/bug-in-prevpow-i-guess/72996)

<div class="topic-metadata">

**Author:** [@reinermartin](https://discourse.julialang.org/u/reinermartin)\
**Replies:** 5\
**Last updated:** [December 12, 2021, 10:56pm UTC](https://discourse.julialang.org/t/bug-in-prevpow-i-guess/72996 "2021-12-12T22:56:43Z")

</div>

Hi, what is the right place to report the following? I think I stumbled onto a simple ‘bug’ (= very unexpected behavior) in prevpow (when solving the latest Project Euler problem). Using Julia 1.7. prevpow(123456789012…

---

## [Tips on code design for writing new packages](https://discourse.julialang.org/t/tips-on-code-design-for-writing-new-packages/72989)

<div class="topic-metadata">

**Author:** [@davibarreira](https://discourse.julialang.org/u/davibarreira)\
**Replies:** 2\
**Last updated:** [December 12, 2021, 8:48pm UTC](https://discourse.julialang.org/t/tips-on-code-design-for-writing-new-packages/72989 "2021-12-12T20:48:23Z")

</div>

When starting a new package, I’m always overwhelmed by the multiple possibilities of how to desig my code. I was wondering what are some good references out there on how “design your code” for package development in Juli…

---

## [Plot with four y-axes (, so two y-axis have to be double)](https://discourse.julialang.org/t/plot-with-four-y-axes-so-two-y-axis-have-to-be-double/72985)

<div class="topic-metadata">

**Author:** [@dadaforpeace](https://discourse.julialang.org/u/dadaforpeace)\
**Replies:** 0\
**Last updated:** [December 12, 2021, 7:28pm UTC](https://discourse.julialang.org/t/plot-with-four-y-axes-so-two-y-axis-have-to-be-double/72985 "2021-12-12T19:28:44Z")

</div>

Hi, I am trying to extend the example found here (Plot with three y-axes (, so one y-axis has to be double) - #10 by dadaforpeace) to four y-axes such that two y-axis have to be drawn double. The data and a jupyter note…

---

## [Performance of Unitful Arrays](https://discourse.julialang.org/t/performance-of-unitful-arrays/52635)

<div class="topic-metadata">

**Author:** [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Replies:** 8\
**Last updated:** [December 12, 2021, 3:57pm UTC](https://discourse.julialang.org/t/performance-of-unitful-arrays/52635 "2021-12-12T15:57:51Z")

</div>

Suppose I have a large matrix M composed of homogeneous Unitful data, and a vector v, which contains homogeneus Unitful data as well. (By Unitful data I mean the data with the types from Unitful.jl) Does the calculation…

---

## [Modify string interpolation](https://discourse.julialang.org/t/modify-string-interpolation/72904)

<div class="topic-metadata">

**Author:** [@Asmund\_Hjulstad](https://discourse.julialang.org/u/Asmund_Hjulstad)\
**Replies:** 4\
**Last updated:** [December 12, 2021, 2:01pm UTC](https://discourse.julialang.org/t/modify-string-interpolation/72904 "2021-12-12T14:01:09Z")

</div>

Is it possible to modify string interpolation using type-specific rules restricted to a specific context? """SELECT \* WHERE { ?s \<$(ns.aa.\_\_str\_\_())\> ?o) } """ outputs "SELECT \* WHERE {\\n?s \<http://example.org/aa\> ?o)…

---

## [How to check if there are at least one true Cartesian index?](https://discourse.julialang.org/t/how-to-check-if-there-are-at-least-one-true-cartesian-index/72961)

<div class="topic-metadata">

**Author:** [@leon](https://discourse.julialang.org/u/leon)\
**Replies:** 4\
**Last updated:** [December 12, 2021, 8:40am UTC](https://discourse.julialang.org/t/how-to-check-if-there-are-at-least-one-true-cartesian-index/72961 "2021-12-12T08:40:42Z")

</div>

I love Cartesian indices because of its performance. One issue I’m not clear is how to check if there are at least one true Cartesian index. For example, if I have a vector as the below: A = \[1, 2, 3, 4, 5\]; My regula…

---

## [Problem with pyplot](https://discourse.julialang.org/t/problem-with-pyplot/72937)

<div class="topic-metadata">

**Author:** [@Xuekui\_wang](https://discourse.julialang.org/u/Xuekui_wang)\
**Replies:** 2\
**Last updated:** [December 12, 2021, 3:48am UTC](https://discourse.julialang.org/t/problem-with-pyplot/72937 "2021-12-12T03:48:29Z")

</div>

When I use pyplot there are erros: PyError ($(Expr(:escape, :(ccall(#= C:\\Users\\Lenovo.julia\\packages\\PyCall\\3fwVL\\src\\pyfncall.jl:43 =# @pysym(:PyObject\_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) \<cla…

---

## [Extract variables from strings](https://discourse.julialang.org/t/extract-variables-from-strings/72881)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 13\
**Last updated:** [December 12, 2021, 1:59am UTC](https://discourse.julialang.org/t/extract-variables-from-strings/72881 "2021-12-12T01:59:49Z")

</div>

I’d like write a macro to extract variables from strings. So writing @string\_extract "test var\_1 and var\_2" "test $x and $y" would set x = "var\_1" y = "var\_2" So, is there a function to convert "test…

---

## [Pushing to a set of structs](https://discourse.julialang.org/t/pushing-to-a-set-of-structs/72945)

<div class="topic-metadata">

**Author:** [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Replies:** 3\
**Last updated:** [December 12, 2021, 1:29am UTC](https://discourse.julialang.org/t/pushing-to-a-set-of-structs/72945 "2021-12-12T01:29:44Z")

</div>

I define my struct as immutable, but it contains a mutable type. Hence when I try to add two of the “same” elements to a set, it adds it (as it should?) struct Hand cards::Vector{Int} end DAG = Set{Hand}() root = H…

---

## [Exotic iteration syntax](https://discourse.julialang.org/t/exotic-iteration-syntax/72948)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 2\
**Last updated:** [December 11, 2021, 10:19pm UTC](https://discourse.julialang.org/t/exotic-iteration-syntax/72948 "2021-12-11T22:19:13Z")

</div>

I’ve never seen this iteration syntax before. It seems that any function application can be used as a variable of iteration, so long as its arguments (but not necessarily the function itself) are defined, and the functio…

---

## [MethodError: Cannot \`convert\` an object of type Vector{Float64} to an object of type Float64](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64/66335)

<div class="topic-metadata">

**Author:** [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Replies:** 11\
**Last updated:** [December 11, 2021, 10:00pm UTC](https://discourse.julialang.org/t/methoderror-cannot-convert-an-object-of-type-vector-float64-to-an-object-of-type-float64/66335 "2021-12-11T22:00:02Z")

</div>

What does this error mean? That an object somewhere in the code is specified as Vector{Float64} and Julia cannot convert it to Float64? I thought it didn’t matter so long as the type was matched (i.e. both Float64).

---

## [Precompilation of developed packages](https://discourse.julialang.org/t/precompilation-of-developed-packages/72785)

<div class="topic-metadata">

**Author:** [@StefanMathis](https://discourse.julialang.org/u/StefanMathis)\
**Replies:** 1\
**Last updated:** [December 11, 2021, 9:59pm UTC](https://discourse.julialang.org/t/precompilation-of-developed-packages/72785 "2021-12-11T21:59:27Z")

</div>

Hello, I have a project in development which is rather large, therefore resulting in long precompilation times when using it for the first time in a fresh Julia REPL session. The project can be separated in multiple ind…

---

## [Why is LLVM missing this constant in a loop?](https://discourse.julialang.org/t/why-is-llvm-missing-this-constant-in-a-loop/72941)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 10\
**Last updated:** [December 11, 2021, 8:16pm UTC](https://discourse.julialang.org/t/why-is-llvm-missing-this-constant-in-a-loop/72941 "2021-12-11T20:16:11Z")

</div>

using BenchmarkTools using LinearAlgebra function f(x,y) z = 0.0 for i in 1:10 xy = x .\* y z += norm(xy) end z end function fopt(x,y) z = 0.0 xy = x .\* y for i in 1:10 …

---

## [Use of Channels (or similar) constructs in parallel processing](https://discourse.julialang.org/t/use-of-channels-or-similar-constructs-in-parallel-processing/18497)

<div class="topic-metadata">

**Author:** [@hesham](https://discourse.julialang.org/u/hesham)\
**Replies:** 4\
**Last updated:** [December 11, 2021, 8:26am UTC](https://discourse.julialang.org/t/use-of-channels-or-similar-constructs-in-parallel-processing/18497 "2021-12-11T08:26:23Z")

</div>

Hi, I have used Julia Channels in real-time processing of data in a pipeline fashion. Each Channel passes data to the next processing step. A simplified example is the code below, one channel for generating random numbe…

---

## [Vector column](https://discourse.julialang.org/t/vector-column/72925)

<div class="topic-metadata">

**Author:** [@biglari](https://discourse.julialang.org/u/biglari)\
**Replies:** 4\
**Last updated:** [December 11, 2021, 8:08am UTC](https://discourse.julialang.org/t/vector-column/72925 "2021-12-11T08:08:39Z")

</div>

Hi, I have a vector that has 100 rows and two columns. I want to select the second column. Julia gives an error with the following command. Can anyone help me? box=\[0,1,0,1\] ninit= 100 pdp = \[LinRange(box\[1\],box\[2\],ni…

---

## [Wrapper type](https://discourse.julialang.org/t/wrapper-type/72915)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 1\
**Last updated:** [December 10, 2021, 10:33pm UTC](https://discourse.julialang.org/t/wrapper-type/72915 "2021-12-10T22:33:58Z")

</div>

I want to make a struct Wrapper{T} x::T end that forwards calls f(w) to f(w.x). What are the options?

---

## [Seemingly unnecessary allocation within for loop](https://discourse.julialang.org/t/seemingly-unnecessary-allocation-within-for-loop/72556)

<div class="topic-metadata">

**Author:** [@mjg](https://discourse.julialang.org/u/mjg)\
**Replies:** 15\
**Last updated:** [December 10, 2021, 9:29pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-allocation-within-for-loop/72556 "2021-12-10T21:29:15Z")

</div>

I’m trying to create a simulation of an elastic string generalized to an arbitrary number of dimensions. To do so I track position and momentum (with an extra array to store the intermediate positions), and use the Euler…

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=507)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=509)
