1.5.4 Writing to a file
With #:out-file, both plot procedures also write the plot to a file, in the format that the file’s extension names: ".png", ".pdf", ".svg" or ".eps", in upper or lower case. They still return the pict. Any other extension breaks their contract:
> (require racket/file) > (define file (make-temporary-file "cv-~a.png")) > (void (plot-cv cv #:out-file file)) > (call-with-input-file file (lambda (in) (read-bytes 4 in))) #"\211PNG"
> (delete-file file) > (plot-cv cv #:out-file "cv.jpg") plot-cv: contract violation
expected: (or/c #f (and/c path-string?
has-image-extension?))
given: "cv.jpg"
in: the #:out-file argument of
(->*
((or/c glmnet-cv? formula-model?))
(#:height
exact-positive-integer?
#:out-file
(or/c
#f
(and/c
path-string?
has-image-extension?))
#:sign-lambda
(or/c -1 1)
#:title
(or/c #f string?)
#:width
exact-positive-integer?)
pict?)
contract from: <pkgs>/glmnet/plot.rkt
blaming: top-level
(assuming the contract is correct)
at: <pkgs>/glmnet/plot.rkt:80:3