def fmla_for_filt(filt):
    """
    transform a set of column filters
    from a dictionary like
        { 'varX':['lv11','lvl2'],...}
    into an R selector expression like
        'varX %in% c("lvl1","lvl2")' & ...
    """
    return ' & '.join([
        '{var} %in% c({lvls})'.format(
            var=k,
            lvls=','.join(map(lambda x:'"%s"' % x, v)) if
            type(v) == list else '"%s"' % v
        ) for k, v in filt.items()
    ])