# Expanding beamer arguments

I have created a new command that takes beamer-arguments (<...>), but I'm not able to pass them on. I suppose it's a \expandafter problem. Does anyone have a clue?

\documentclass{beamer}
\usepackage{tikz}

\pgfkeys{/mypgf/.cd, arg/.store in = \arg}

\newcommand<>\img[2][]{
\pgfkeys{/mypgf/.cd, #1}

{
\def\options{} % set options to something useful based on #1

% This works:
\expandafter\includegraphics\expandafter[\options]{#2}

% But not when I try to add the beamer argument:
\expandafter\includegraphics#3\expandafter[\options]{#2}
}
}

\begin{document}

\img<2-4>[arg=val]{example-image}

\end{document}
• do you intend the macro to insert a paragraph break before image? (all the white space in the definition has an effect) – David Carlisle Mar 2 '14 at 18:59