# General Usage

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

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

**Page:** 330

---

## [How to test if package is installed](https://discourse.julialang.org/t/how-to-test-if-package-is-installed/3508)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 23\
**Last updated:** [February 13, 2023, 10:00am UTC](https://discourse.julialang.org/t/how-to-test-if-package-is-installed/3508 "2023-02-13T10:00:07Z")

</div>

What’s the recommended API for testing if a package (which may not be registed) is installed? I have seen two versions floating around: "somepackage" ∈ keys(Pkg.installed()) and isdir(Pkg.dir("somepackage")) The seco…

---

## [Proper way to identify variables/models with functions](https://discourse.julialang.org/t/proper-way-to-identify-variables-models-with-functions/94535)

<div class="topic-metadata">

**Author:** [@PaterPen](https://discourse.julialang.org/u/PaterPen)\
**Replies:** 1\
**Last updated:** [February 13, 2023, 8:03am UTC](https://discourse.julialang.org/t/proper-way-to-identify-variables-models-with-functions/94535 "2023-02-13T08:03:37Z")

</div>

Recently I revisited some old Julia code of mine and wondered how to implement it properly. The setting is: I have a model struct which holds some model definition. Let’s say, each model just describes some system of eq…

---

## [Printing zero elements in lines of a sparse matrix](https://discourse.julialang.org/t/printing-zero-elements-in-lines-of-a-sparse-matrix/94530)

<div class="topic-metadata">

**Author:** [@Gravlax](https://discourse.julialang.org/u/Gravlax)\
**Replies:** 6\
**Last updated:** [February 13, 2023, 7:55am UTC](https://discourse.julialang.org/t/printing-zero-elements-in-lines-of-a-sparse-matrix/94530 "2023-02-13T07:55:43Z")

</div>

Dear all, I would like to print the non-zero elements along a give line of a sparse matrix. In fact I’m trying to find a way to reproduce the behaviour of MATLAB. For example, here’s how a line is printed in MATLAB, it…

---

## [Unexpected result from short-circuiting (inline if)](https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400)

<div class="topic-metadata">

**Author:** [@CarlosST](https://discourse.julialang.org/u/CarlosST)\
**Replies:** 9\
**Last updated:** [February 13, 2023, 5:01am UTC](https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400 "2023-02-13T05:01:09Z")

</div>

I’m quite familiar with using short-circuit evaluation as an inline if, and my understanding was that writing cond && (expression) is exactly identical to the more traditional: if cond expression; end However, I fo…

---

## [Why can't the compiler constant-fold operations on BigInt and BigFloat?](https://discourse.julialang.org/t/why-cant-the-compiler-constant-fold-operations-on-bigint-and-bigfloat/94447)

<div class="topic-metadata">

**Author:** [@bobcassels](https://discourse.julialang.org/u/bobcassels)\
**Replies:** 14\
**Last updated:** [February 13, 2023, 1:44am UTC](https://discourse.julialang.org/t/why-cant-the-compiler-constant-fold-operations-on-bigint-and-bigfloat/94447 "2023-02-13T01:44:49Z")

</div>

wtf(x) = x \* Float64(big(12.34) / big(180)^3) @code\_llvm wtf(1.0) shows runtime calls to do the big-ifying, and the exponentiation. If I remove the calls to big, it constant-folds just fine.

---

## [Compile C code with Julia package](https://discourse.julialang.org/t/compile-c-code-with-julia-package/91305)

<div class="topic-metadata">

**Author:** [@PaterPen](https://discourse.julialang.org/u/PaterPen)\
**Replies:** 8\
**Last updated:** [February 13, 2023, 1:02am UTC](https://discourse.julialang.org/t/compile-c-code-with-julia-package/91305 "2023-02-13T01:02:32Z")

</div>

Hi, I am currently thinking about migrating an R package with underlying C/C++ code to a Julia package. However, in the short term the large C/C++ codebase should be reused and therefore is intended to be called from wi…

---

## [Documenting packages](https://discourse.julialang.org/t/documenting-packages/94493)

<div class="topic-metadata">

**Author:** [@dscolby](https://discourse.julialang.org/u/dscolby)\
**Replies:** 8\
**Last updated:** [February 13, 2023, 12:14am UTC](https://discourse.julialang.org/t/documenting-packages/94493 "2023-02-13T00:14:59Z")

</div>

I just created a new package but I’m having a lot of trouble getting the documentation to render with Documenter.jl. When I deploy it to GitHub pages it displays the readme instead of the index.md file in my docs/src dir…

---

## [Late evaluation of expression as anymous function](https://discourse.julialang.org/t/late-evaluation-of-expression-as-anymous-function/94516)

<div class="topic-metadata">

**Author:** [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Replies:** 11\
**Last updated:** [February 12, 2023, 7:35pm UTC](https://discourse.julialang.org/t/late-evaluation-of-expression-as-anymous-function/94516 "2023-02-12T19:35:32Z")

</div>

I want to iteratively build a function, but I can’t figure out how. I’ll try and give a non-working example hoping that this helps explain what I am trying to do. mydata = Dict(:a =\> 1, :b =\> 2, :c =\> 3) function build…

---

## [How do I concretely type a field in a struct dynamically?](https://discourse.julialang.org/t/how-do-i-concretely-type-a-field-in-a-struct-dynamically/94524)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 2\
**Last updated:** [February 12, 2023, 6:12pm UTC](https://discourse.julialang.org/t/how-do-i-concretely-type-a-field-in-a-struct-dynamically/94524 "2023-02-12T18:12:30Z")

</div>

Hello! For performance reasons I have to concretely type this field in my struct; struct Test{I,D} Stencil::Vector{Tuple{repeat(\[I\],D)...}} end I’ve tried to do as follows but it errors out. “I” is the type I wish…

---

## [Problem with SymPy](https://discourse.julialang.org/t/problem-with-sympy/94525)

<div class="topic-metadata">

**Author:** [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Replies:** 0\
**Last updated:** [February 12, 2023, 6:11pm UTC](https://discourse.julialang.org/t/problem-with-sympy/94525 "2023-02-12T18:11:01Z")

</div>

I am having the following problem. using SymPy @syms x y f = -integrate(sin(y)/(abs(y)-PI)^3,(y,x,PI/6)) + integrate(cos(y-x)/(abs(y)-PI)^3,(y,x,PI/6)) + integrate(sin(y)\*cos(y-x)/(abs(y)-PI)^3,(y,x,PI/6)) - integrate(1…

---

## [How to loop over vector with varying inner-dimensions?](https://discourse.julialang.org/t/how-to-loop-over-vector-with-varying-inner-dimensions/94517)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 5\
**Last updated:** [February 12, 2023, 5:52pm UTC](https://discourse.julialang.org/t/how-to-loop-over-vector-with-varying-inner-dimensions/94517 "2023-02-12T17:52:08Z")

</div>

Hello! Suppose I have: Values = SVector{3, Int64}\[\[3, 0, 1\], \[2, 3, 4\], \[3, 4, 3\], \[2, 3, 2\], \[0, 2, 2\], \[4, 2, 4\], \[4, 2, 4\], \[0, 3, 3\], \[4, 2, 0\], \[2, 2, 0\], \[0, 0, 0\], \[0, 0, 2\], \[2, 1, 4\], \[2, 0, 4\], \[1, 2, 2\], \[1,…

---

## [Plots not working when using PackageCompiler](https://discourse.julialang.org/t/plots-not-working-when-using-packagecompiler/94480)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 1\
**Last updated:** [February 12, 2023, 2:48pm UTC](https://discourse.julialang.org/t/plots-not-working-when-using-packagecompiler/94480 "2023-02-12T14:48:07Z")

</div>

I have a very simple piece of code: using Plots x=\[1,2,3,4,5\] y=\[1,2,3,4,5\] plot(x,y) Works fine. When I now use a system image it stops to work. Instead of a plot window I get the text output: Plot{Plots.GRBackend()…

---

## [Where is Fourier()](https://discourse.julialang.org/t/where-is-fourier/94512)

<div class="topic-metadata">

**Author:** [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Replies:** 5\
**Last updated:** [February 12, 2023, 2:09pm UTC](https://discourse.julialang.org/t/where-is-fourier/94512 "2023-02-12T14:09:53Z")

</div>

In the demo on spectral methods found at https://docs.sciml.ai/SciMLBenchmarksOutput/stable/MOLPDE/burgers\_spectral\_wpd/ there is a call to Fourier(). I cannot figure out which module it is in. Could somebody please l…

---

## [Limit output in Documenter when displaying a DataFrame](https://discourse.julialang.org/t/limit-output-in-documenter-when-displaying-a-dataframe/94503)

<div class="topic-metadata">

**Author:** [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Replies:** 3\
**Last updated:** [February 12, 2023, 12:06pm UTC](https://discourse.julialang.org/t/limit-output-in-documenter-when-displaying-a-dataframe/94503 "2023-02-12T12:06:33Z")

</div>

In a .md file for Documenter if I do the following, \`\`\`\`@example dataset\_movies using DataFrames, RDatasets movies = dataset("ggplot2", "movies") \`\`\`\` Then when building with makedocs(…) I get a file of size …

---

## [How do I extract number of dimensions and type from a StaticArray?](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 3\
**Last updated:** [February 12, 2023, 9:25am UTC](https://discourse.julialang.org/t/how-do-i-extract-number-of-dimensions-and-type-from-a-staticarray/94497 "2023-02-12T09:25:48Z")

</div>

Hello! Suppose I have: n, d = 100, 2 p = rand(SVector{d,Float64},n) p = rand(SVector{d,Float64},n) 100-element Vector{SVector{2, Float64}}: \[0.45095181425482966, 0.07762277325569156\] \[0.08059534744395058, 0…

---

## [Do we have a "sizeforce!"?](https://discourse.julialang.org/t/do-we-have-a-sizeforce/94496)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 2\
**Last updated:** [February 12, 2023, 8:59am UTC](https://discourse.julialang.org/t/do-we-have-a-sizeforce/94496 "2023-02-12T08:59:26Z")

</div>

Hello! Reading in the help of sizehint!: I notice how it is only a “suggestive” procedure and that it may do it. Is there a way to force it? I know I can preallocate arrays my self. For less code complexity, I had …

---

## [Type stability issues when broadcasting](https://discourse.julialang.org/t/type-stability-issues-when-broadcasting/92715)

<div class="topic-metadata">

**Author:** [@jpdoane](https://discourse.julialang.org/u/jpdoane)\
**Replies:** 4\
**Last updated:** [February 12, 2023, 8:39am UTC](https://discourse.julialang.org/t/type-stability-issues-when-broadcasting/92715 "2023-02-12T08:39:09Z")

</div>

I am seeing some odd type instability issues when broadcasting. Simple functions seem to become type-unstable when broadcasting over multiple views: f1(x::AbstractVector{T}) where T = 1 f2(x::AbstractVector{T}) where T…

---

## [Error when doing integration with QuadGK](https://discourse.julialang.org/t/error-when-doing-integration-with-quadgk/94487)

<div class="topic-metadata">

**Author:** [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Replies:** 1\
**Last updated:** [February 12, 2023, 4:41am UTC](https://discourse.julialang.org/t/error-when-doing-integration-with-quadgk/94487 "2023-02-12T04:41:52Z")

</div>

I used the following code using QuadGK v = quadgk(x-\>cos(x)^2/((x+1)\*(x^2-x+1)),-pi,0)\[1\] and got the error below ERROR: DomainError with -1.0000000000000009: integrand produced Inf in the interval (-1.00000000000000…

---

## [Plots is not plotting correctly](https://discourse.julialang.org/t/plots-is-not-plotting-correctly/94477)

<div class="topic-metadata">

**Author:** [@mmj](https://discourse.julialang.org/u/mmj)\
**Replies:** 6\
**Last updated:** [February 12, 2023, 12:47am UTC](https://discourse.julialang.org/t/plots-is-not-plotting-correctly/94477 "2023-02-12T00:47:34Z")

</div>

Hello. This is a simple problem, but I have not found any solutions on it yet. I am very new to Plots. I am using Plots on a Pluto Notebook but I have been facing certain difficulty with its syntax. I tried to do a sim…

---

## [PackageCompiler: Integration of mingw-w64](https://discourse.julialang.org/t/packagecompiler-integration-of-mingw-w64/94448)

<div class="topic-metadata">

**Author:** [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Replies:** 1\
**Last updated:** [February 11, 2023, 9:18pm UTC](https://discourse.julialang.org/t/packagecompiler-integration-of-mingw-w64/94448 "2023-02-11T21:18:30Z")

</div>

I have problems to integrate properly the mingw-w64 compiler and header files into my project for application compiling via PackageCompiler. I found one tread in the package home page: compile\_app() fails to build if…

---

## [Package to mollify a function?](https://discourse.julialang.org/t/package-to-mollify-a-function/94467)

<div class="topic-metadata">

**Author:** [@Masacroso](https://discourse.julialang.org/u/Masacroso)\
**Replies:** 6\
**Last updated:** [February 11, 2023, 6:26pm UTC](https://discourse.julialang.org/t/package-to-mollify-a-function/94467 "2023-02-11T18:26:06Z")

</div>

Hi, I was searching in the web but I didn’t found something about how to mollify a mathematical function, using any custom mollifier, in Julia. So my question is: there is a package to do that? If not, there is a way to…

---

## [Strange behavior of SymPy in VS Code](https://discourse.julialang.org/t/strange-behavior-of-sympy-in-vs-code/94451)

<div class="topic-metadata">

**Author:** [@Firstname\_Lastname](https://discourse.julialang.org/u/Firstname_Lastname)\
**Replies:** 5\
**Last updated:** [February 11, 2023, 4:09pm UTC](https://discourse.julialang.org/t/strange-behavior-of-sympy-in-vs-code/94451 "2023-02-11T16:09:04Z")

</div>

In VS Code, I used the following code using SymPy @sysm x y f(x,y) = sin(y-x) df = sympy.diff(f(x,y),x) # it outputs \`- cos(x-y)\`: correct df(PI/2,y) # it output \`-sin(y)\`: correct df(x,PI/2) # it outputs \`-1\`: wr…

---

## [FFT documentation](https://discourse.julialang.org/t/fft-documentation/94431)

<div class="topic-metadata">

**Author:** [@Cevheriferd](https://discourse.julialang.org/u/Cevheriferd)\
**Replies:** 4\
**Last updated:** [February 11, 2023, 3:00pm UTC](https://discourse.julialang.org/t/fft-documentation/94431 "2023-02-11T15:00:24Z")

</div>

Hi I have a very general question. As far as I understand AbstractFFTs is the main package in Julia to perform FFTs. Why doesn’t the documentation of this package show up when searching it several search engines? The sea…

---

## [How to define my own "unique" function?](https://discourse.julialang.org/t/how-to-define-my-own-unique-function/94464)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 3\
**Last updated:** [February 11, 2023, 1:05pm UTC](https://discourse.julialang.org/t/how-to-define-my-own-unique-function/94464 "2023-02-11T13:05:46Z")

</div>

Hello! Suppose I have a list of tuples given as: ps 17-element Vector{Tuple{Int64, Int64, Float64}}: (6, 1, 0.1943167542320367) (6, 7, 0.3711794598818039) (6, 3, 0.24015959913323964) (3, 1, 0.10660277812749026) (3…

---

## [Error when installing the DifferentialEquations package](https://discourse.julialang.org/t/error-when-installing-the-differentialequations-package/94437)

<div class="topic-metadata">

**Author:** [@Vidianos](https://discourse.julialang.org/u/Vidianos)\
**Replies:** 4\
**Last updated:** [February 11, 2023, 10:50am UTC](https://discourse.julialang.org/t/error-when-installing-the-differentialequations-package/94437 "2023-02-11T10:50:46Z")

</div>

I want to transition from Matlab to Julia and I am trying to install the DifferentialEquations package. I am getting an error which I am not certain how to fix. Here is the error message \[ Info: Precompiling Differentia…

---

## [Eliminating of consecutive columns with the same values, in two separate vectors with same length and dependant on that accordingly for for a third vector with same length](https://discourse.julialang.org/t/eliminating-of-consecutive-columns-with-the-same-values-in-two-separate-vectors-with-same-length-and-dependant-on-that-accordingly-for-for-a-third-vector-with-same-length/94422)

<div class="topic-metadata">

**Author:** [@ratwolf](https://discourse.julialang.org/u/ratwolf)\
**Replies:** 9\
**Last updated:** [February 11, 2023, 7:11am UTC](https://discourse.julialang.org/t/eliminating-of-consecutive-columns-with-the-same-values-in-two-separate-vectors-with-same-length-and-dependant-on-that-accordingly-for-for-a-third-vector-with-same-length/94422 "2023-02-11T07:11:20Z")

</div>

eliminating of consecutive columns with the same values, in two separate vectors with same length and dependant on that accordingly for for a third vector with same length. Example: x = \[1, 2, 3, 2, 4, 5, 6, 3, 7…\] y…

---

## [Node.js 12 actions deprecation warning on github](https://discourse.julialang.org/t/node-js-12-actions-deprecation-warning-on-github/88718)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [February 11, 2023, 5:46am UTC](https://discourse.julialang.org/t/node-js-12-actions-deprecation-warning-on-github/88718 "2023-02-11T05:46:05Z")

</div>

In several CI runs, I see a warning like Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. …

---

## [How to pass all the variables defined within a function to a nested function?](https://discourse.julialang.org/t/how-to-pass-all-the-variables-defined-within-a-function-to-a-nested-function/94418)

<div class="topic-metadata">

**Author:** [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Replies:** 3\
**Last updated:** [February 11, 2023, 4:11am UTC](https://discourse.julialang.org/t/how-to-pass-all-the-variables-defined-within-a-function-to-a-nested-function/94418 "2023-02-11T04:11:41Z")

</div>

Hi there, I am trying to pass all the variables defined within a function (say foo) to a nested function (say bar) as arguments. Something along the lines of function foo(arg1, arg2; kwarg1=1, kwarg2=2) # do somet…

---

## [How do I choose between QuadGK and Cubature when I do singular integral of a complex-valued function?](https://discourse.julialang.org/t/how-do-i-choose-between-quadgk-and-cubature-when-i-do-singular-integral-of-a-complex-valued-function/94198)

<div class="topic-metadata">

**Author:** [@f1974939505](https://discourse.julialang.org/u/f1974939505)\
**Replies:** 4\
**Last updated:** [February 11, 2023, 1:10am UTC](https://discourse.julialang.org/t/how-do-i-choose-between-quadgk-and-cubature-when-i-do-singular-integral-of-a-complex-valued-function/94198 "2023-02-11T01:10:23Z")

</div>

A simple example is f(x) = 1 / (x + im\*10^(-6)) and calculate the integral of f(x) from -1 to 1. How do I write the Julia code? Note that I don’t want to substitute f(x) with a delta function here.

---

## [What causes this performance loss when using value types?](https://discourse.julialang.org/t/what-causes-this-performance-loss-when-using-value-types/94065)

<div class="topic-metadata">

**Author:** [@akrishnamoorthy](https://discourse.julialang.org/u/akrishnamoorthy)\
**Replies:** 3\
**Last updated:** [February 10, 2023, 11:50pm UTC](https://discourse.julialang.org/t/what-causes-this-performance-loss-when-using-value-types/94065 "2023-02-10T23:50:42Z")

</div>

The following are two implementations of the factorial function: fact1(n) = fact1(Val(n)) fact1(::Val{n}) where {n} = n\*fact1(Val(n-1)) fact1(::Val{1}) = 1 and fact2(n) = n==1 ? 1 : n\*fact2(n-1) This may be subjectiv…

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

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