Internals
GBIF.validate_occurrence_query Function
validate_occurrence_query(query::Pair)
Checks that the queries for occurrences searches are well formatted.
This is used internally.
Everything this function does is derived from the GBIF API documentation, including (and especially) the values for enum types. This modifies the queryset. Filters that are not allowed are removed, and filters that have incorrect values are dropped too.
This feels like the most conservative option – the user can always filter the results when they are returned.
Base.show Function
show([io::IO = stdout], x)
Write a text representation of a value x
to the output stream io
. New types T
should overload show(io::IO, x::T)
. The representation used by show
generally includes Julia-specific formatting and type information, and should be parseable Julia code when possible.
repr
returns the output of show
as a string.
For a more verbose human-readable text output for objects of type T
, define show(io::IO, ::MIME"text/plain", ::T)
in addition. Checking the :compact
IOContext
key (often checked as get(io, :compact, false)::Bool
) of io
in such methods is recommended, since some containers show their elements by calling this method with :compact => true
.
See also print
, which writes un-decorated representations.
Examples
julia> show("Hello World!")
"Hello World!"
julia> print("Hello World!")
Hello World!
show(io::IO, mime, x)
The display
functions ultimately call show
in order to write an object x
as a given mime
type to a given I/O stream io
(usually a memory buffer), if possible. In order to provide a rich multimedia representation of a user-defined type T
, it is only necessary to define a new show
method for T
, via: show(io, ::MIME"mime", x::T) = ...
, where mime
is a MIME-type string and the function body calls write
(or similar) to write that representation of x
to io
. (Note that the MIME""
notation only supports literal strings; to construct MIME
types in a more flexible manner use MIME{Symbol("")}
.)
For example, if you define a MyImage
type and know how to write it to a PNG file, you could define a function show(io, ::MIME"image/png", x::MyImage) = ...
to allow your images to be displayed on any PNG-capable AbstractDisplay
(such as IJulia). As usual, be sure to import Base.show
in order to add new methods to the built-in Julia function show
.
Technically, the MIME"mime"
macro defines a singleton type for the given mime
string, which allows us to exploit Julia's dispatch mechanisms in determining how to display objects of any given type.
The default MIME type is MIME"text/plain"
. There is a fallback definition for text/plain
output that calls show
with 2 arguments, so it is not always necessary to add a method for that case. If a type benefits from custom human-readable output though, show(::IO, ::MIME"text/plain", ::T)
should be defined. For example, the Day
type uses 1 day
as the output for the text/plain
MIME type, and Day(1)
as the output of 2-argument show
.
Examples
julia> struct Day
n::Int
end
julia> Base.show(io::IO, ::MIME"text/plain", d::Day) = print(io, d.n, " day")
julia> Day(1)
1 day
Container types generally implement 3-argument show
by calling show(io, MIME"text/plain"(), x)
for elements x
, with :compact => true
set in an IOContext
passed as the first argument.
Show an occurrence
show(io::IO, o::GBIFRecord)
Displays the key, the taxon name, and the country of observation.
Show several occurrences
show(io::IO, o::GBIFRecords)
Displays the total number, and the number of currently unmasked records.
Show a taxonomic record
show(io::IO, t::GBIFTaxon)
Displays the taxon name.
show([io::IO, ]df::AbstractDataFrame;
allrows::Bool = !get(io, :limit, false),
allcols::Bool = !get(io, :limit, false),
allgroups::Bool = !get(io, :limit, false),
rowlabel::Symbol = :Row,
summary::Bool = true,
eltypes::Bool = true,
truncate::Int = 32,
kwargs...)
Render a data frame to an I/O stream. The specific visual representation chosen depends on the width of the display.
If io
is omitted, the result is printed to stdout
, and allrows
, allcols
and allgroups
default to false
.
Arguments
io::IO
: The I/O stream to whichdf
will be printed.df::AbstractDataFrame
: The data frame to print.allrows::Bool
: Whether to print all rows, rather than a subset that fits the device height. By default this is the case only ifio
does not have theIOContext
propertylimit
set.allcols::Bool
: Whether to print all columns, rather than a subset that fits the device width. By default this is the case only ifio
does not have theIOContext
propertylimit
set.allgroups::Bool
: Whether to print all groups rather than the first and last, whendf
is aGroupedDataFrame
. By default this is the case only ifio
does not have theIOContext
propertylimit
set.rowlabel::Symbol = :Row
: The label to use for the column containing row numbers.summary::Bool = true
: Whether to print a brief string summary of the data frame.eltypes::Bool = true
: Whether to print the column types under column names.truncate::Int = 32
: the maximal display width the output can use before being truncated (in thetextwidth
sense, excluding…
). Iftruncate
is 0 or less, no truncation is applied.kwargs...
: Any keyword argument supported by the functionpretty_table
of PrettyTables.jl can be passed here to customize the output.
Examples
julia> using DataFrames
julia> df = DataFrame(A=1:3, B=["x", "y", "z"]);
julia> show(df, show_row_number=false)
3×2 DataFrame
A B
Int64 String
───────────────
1 x
2 y
3 z
show(io::IO, mime::MIME, df::AbstractDataFrame)
Render a data frame to an I/O stream in MIME type mime
.
Arguments
io::IO
: The I/O stream to whichdf
will be printed.mime::MIME
: supported MIME types are:"text/plain"
,"text/html"
,"text/latex"
,"text/csv"
,"text/tab-separated-values"
(the last two MIME types do not support showing#undef
values)df::AbstractDataFrame
: The data frame to print.
Additionally selected MIME types support passing the following keyword arguments:
MIME type
"text/plain"
accepts all listed keyword arguments and their behavior is identical as forshow(::IO, ::AbstractDataFrame)
MIME type
"text/html"
accepts the following keyword arguments:eltypes::Bool = true
: Whether to print the column types under column names.summary::Bool = true
: Whether to print a brief string summary of the data frame.max_column_width::AbstractString = ""
: The maximum column width. It must be a string containing a valid CSS length. For example, passing "100px" will limit the width of all columns to 100 pixels. If empty, the columns will be rendered without limits.kwargs...
: Any keyword argument supported by the functionpretty_table
of PrettyTables.jl can be passed here to customize the output.
Examples
julia> show(stdout, MIME("text/latex"), DataFrame(A=1:3, B=["x", "y", "z"]))
\begin{tabular}{r|cc}
& A & B\\
\hline
& Int64 & String\\
\hline
1 & 1 & x \\
2 & 2 & y \\
3 & 3 & z \\
\end{tabular}
14
julia> show(stdout, MIME("text/csv"), DataFrame(A=1:3, B=["x", "y", "z"]))
"A","B"
1,"x"
2,"y"
3,"z"
show(io::IO, x::Quantity)
Show a unitful quantity by calling showval
on the numeric value, appending a space, and then calling show
on a units object U()
.
show(io::IO, x::Unitlike)
Call Unitful.showrep
on each object in the tuple that is the type variable of a Unitful.Units
or Unitful.Dimensions
object.