<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def install(pkg, channel=None, refresh=False):
    '''
    Install the specified snap package from the specified channel.
    Returns a dictionary of "result" and "output".

    pkg
        The snap package name

    channel
        Optional. The snap channel to install from, eg "beta"

    refresh : False
        If True, use "snap refresh" instead of "snap install".
        This allows changing the channel of a previously installed package.
    '''
    args = []
    ret = {'result': None, 'output': ""}

    if refresh:
        cmd = 'refresh'
    else:
        cmd = 'install'

    if channel:
        args.append('--channel=' + channel)

    try:
        # Try to run it, merging stderr into output
        ret['output'] = subprocess.check_output([SNAP_BINARY_NAME, cmd, pkg] + args, stderr=subprocess.STDOUT)
        ret['result'] = True
    except subprocess.CalledProcessError as e:
        ret['output'] = e.output
        ret['result'] = False

    return ret