R の switch ステートメントは、たとえば C++ のように機能するように設計されていないことは知っていますが、ドキュメントを読んだところ、以下が機能しない理由がわかりません。
file.types <- c('bmp', 'jpeg', 'png', 'tiff', 'eps', 'pdf', 'ps')
if(tolower(file.type) %in% file.types) {
switch(file.type,
bmp = bmp(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
jpeg = jpeg(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
png = png(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
tiff = tiff(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
eps = postscript(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
pdf = postscript(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1])
ps = postscript(filename=paste(file.location, file.name, '.',
file.type, sep=''),
width=res[2], height=res[1]))
} else {
stop(paste(file.type,' is not supported', sep=''))
}
file.type が「jpeg」の場合、次のエラーが発生します
Error: unexpected symbol in:
" bmp = {bmp(filename=paste(file.location, file.name, '.', file.type, sep=''), width=res[2], height=res[1])}
jpeg"
洞察に感謝します!