R/put.fitskey.R

Defines functions put.fitskey

Documented in put.fitskey

put.fitskey = function(key, value, hdr){
    
    # create key/value vectors
    k = rep(NA, max(length(key),length(value)))
    v = rep(NA, max(length(key),length(value)))
    k[1:length(key)] = key
    v[1:length(value)] = value
    
    # update pre-existing keys
    if(any(k %in% hdr[,"key"])){
        
        # determine order of vectors
        inhdr = which(hdr[,"key"] %in% k)
        inkey = which(k %in% hdr[,"key"])
        matched = inhdr[match(hdr[inhdr,"key"],k[inkey])]
        
        # update header
        hdr[matched,"value"] = v[inkey]
        
    }
    
    # create new keys
    if(any(!k %in% hdr[,"key"])){
        
        # determine new keys
        outhdr = which(!k %in% hdr[,"key"])
        
        # append to header
        hdr = rbind(hdr, c(key=k[outhdr], value=v[outhdr], comment=""))
        
    }
    
    # return results
    return(hdr)
    
}

Try the astro package in your browser

Any scripts or data that you put into this service are public.

astro documentation built on May 2, 2019, 2:14 a.m.