getopt does not parse optional arguments to parameters

Although not mentioned in glibc documentation or getopt man page, optional arguments to long style command line parameters require ‘equals sign’ (=). Space separating the optional argument from the parameter does not work. An example run with the test code: $ ./respond –praise John Kudos to John $ ./respond –praise=John Kudos to John $ ./respond … Read more

Named tuple and default values for optional keyword arguments

Python 3.7 Use the defaults parameter. >>> from collections import namedtuple >>> fields = (‘val’, ‘left’, ‘right’) >>> Node = namedtuple(‘Node’, fields, defaults=(None,) * len(fields)) >>> Node() Node(val=None, left=None, right=None) Or better yet, use the new dataclasses library, which is much nicer than namedtuple. >>> from dataclasses import dataclass >>> from typing import Any >>> … Read more

Is there a way to use two ‘…’ statements in a function in R?

An automatic way: foo.plot <- function(x,y,…) { lnames <- names(formals(legend)) pnames <- c(names(formals(plot.default)), names(par())) dots <- list(…) do.call(‘plot’, c(list(x = x, y = x), dots[names(dots) %in% pnames])) do.call(‘legend’, c(“bottomleft”, “bar”, pch = 1, dots[names(dots) %in% lnames])) } pch must be filtered from the lnames to avoid duplication in the legend call in case the user … Read more