What is the problem with this Julia code?

I wrote a function that plots several boxplots, ordered by the orders of a factor (categorical variable). It works, but VSCode keeps telling me there is a problem in one of the lines. Would someone know the reason?

Here is the code:


using DataFrames, StatsPlots

varnames = ["Winter", "Spring", "Summer", "Fall"]
df = DataFrame(
    :variable => categorical(repeat(varnames, 20), levels = varnames),
    :value => rand(80)
)

function boxplot_ordered(
    df::DataFrame;
    variable_col::Symbol = :variable,
    value_col::Symbol = :value,
    plotsize::Tuple{Int64,Int64} = (800, 600) # ctrl_parms.PlotSize
)
    msg = "`variable_col` is not a column name of `df`"
    @assert string(variable_col) in names(df) msg

    msg = "`value_col` is not a column name of `df`"
    @assert string(value_col) in names(df) msg

    msg = "Column `variable_col` of `df` is not categorical"
    @assert typeof(df[!, variable_col]) <: CategoricalVector msg

    variable_order = string.(levels(df[!, variable_col]))
    v = collect(1:length(variable_order))
    d = Dict(zip(variable_order, v))
    
    dfc = select(
        df,
        variable_col => ByRow(x -> d[x]) => :Order,
        variable_col => (x -> (string.(x))) => variable_col,
        value_col,
    )

    p = boxplot(
        dfc.Order,
        dfc[!, value_col],
        legend = false,
        size = plotsize
    )
    plot!(xticks = (v, variable_order)) # THIS IS THE LINE FLAGGED AS A PROBLEM

    display(p)

    return p
end # boxplot_ordered

boxplot_ordered(df)

I would suggest posting the error message.

1 Like

I would assume the problem is with VSCode, and not the Julia code.

Works for me. I didn’t get any error when running your code.

I think it is not an error but problem with VS code in windows. I also get the blue underline in windows but it is not present on Linux machine.
plot_warning

I ran it on VSCode in Windows and had no issue.

I don’t get an error when running the code. It is just that VSCode inserts that line in the list of Problems, with the message “Possible method call error.”

The message is "“Possible method call error.” It is not an error message, The function runs with no problems. It is a Problem flagged by VSCode.

Probably related to this issue:

https://github.com/julia-vscode/julia-vscode/issues/1576

It is the problem with linter. So the code will work.