modifyHeader {FITSio}R Documentation

Modify and edit comments and keyword-value pairs in FITS header


Functions to modify and edit keyword = value pairs in FITS header: newKwv creates keyword = value / comment line for header; addKwv adds keyword = value / comment to header; delKwv deletes keyword = value / comment from header; modVal modifies value in keyword = value / comment in header; addComment adds COMMENT line to header; addHistory adds HISTORY line to header.


newKwv(keyw, val, note)

addKwv(keyw, val, note, headerName)

delKwv(keyw, headerName)

modVal(keyw, val, note, headerName)

addComment(comment, headerName)

addHistory(history, headerName)



Keyword, 8 character limit (FITS specification)


Value for keyword


Optional descriptive note following keyword = value


Comment text string


History text string


Header card images (vector)


All keywords will be converted to upper case (FITS convention) and truncated to 8 characters. There is no checking for duplicate keywords. The default numerical format for values is 20.14g; if other formats are needed, format separately and write the text string as the value (see examples). Similar work-arounds may be necessary for long note strings (see examples).


New card image for newKwv, otherwise modified header card images.


It is also possible to operate directly on the vector of header card images. These functions are simply for convenience in maintaining the correct header formatting. No END card is needed in the header card images; that is added by closeHdr, which must be run to complete the header formatting.


A. Harris

See Also

readFITS, readFITSheader, closeHdr


# Make header from scratch, then add, modify, delete card images.
header <- newKwv('KEYWORD', 'VALUE', 'NOTE')
header <- addKwv('test1', 'plot size', header=header)
header <- addKwv('test2', 4294.95397809807, 'number', header=header)
header <- addKwv('test3', 4.29495397809807e50, 'big number', header=header)
header <- addKwv('test4', -4.29495397809807e50, 'big number', header=header)
header <- addKwv('test5', 'this is a very long value', 'number', header=header)
header <- addKwv('test6',
   'this is a very very very very very very very very long value',
   'note', header=header)
header <- addKwv('test7', 'value',
   'very very very very very very very very very very long comment',
header <- addKwv('test8', '0123456789112345678921234567893123456',
   'format long number as string', header=header)
header <- addKwv('apostrophe', 'o\'\'malley',
   'apostrophes are doubled in value strings', header=header)
for (i in 1:4) {
   header <- addKwv(paste('test', 100+i, sep=''), 100+i, header=header)
header <- delKwv('test103', header=header)
header <- addComment('TEST103 should be missing from header', header=header)
header <- addHistory('This header generated by modifyHeader example',

# show header

[Package FITSio version 2.1-6 Index]