Open discoleo opened 1 year ago
The function read_blocks (and possibly other functions) contains the following code: if(!is.null(startrow) & !all(is.numeric(startrow))) { startrow[!is.numeric(startrow)] <- from_excel(startrow[!is.numeric(startrow)]) startrow <- as.numeric(startrow) }
This code could be moved entirely to a helper function: as.numletter.list = function(x) { if( ! is.null(x) && ! all(is.numeric(x))) { isNotNum = ! is.numeric(x); x[isNotNum] = as.numletter(x[isNotNum]); x = as.numeric(x); # may be unnecessary; } return(x); }
Note:
Function from_excel
The code converts a string into ASCII codes and then combines the ASCII codes into a single number. There are alternative ways to implement this.
R Function charToRaw
Note:
R Code
as.numletter = function(x) { lapply(x, function(s) { tmp = as.numeric(charToRaw(s)); tmp = ifelse(tmp >= 97, tmp - 96, tmp - 64); return(tmp); }); }
Example:
Encoding of Result
It is a different question, if the result should be kept as an array of integer-codes; or to combine the codes to a single number: but this latter solution requires continuous conversions back and force!
Note: