Displaying 2 results from an estimated 2 matches for "load_file1".
Did you mean:
load_file
2008 Jan 18
2
NameError when using alias_method -- but method exists?
Hello Rubyists,
I am a bit stumped here. I want to extend the ''load_file'' method in the
YAML module. Following along with the PickAxe example of making old
methods do new things, I try this in irb:
>> module YAML
>> alias_method :orig_load_f, :load_file
>> def load_file(*args)
>> contents = orig_load_f(*args)
>>
2012 Apr 01
1
scan() vs readChar() speed
...ally fast.
However, it returns a long character string, where I really want
numeric values. I can use as.numeric(strsplit()), but to my complete
surprise it is faster to run scan() on this text string. Consider the
following comparison (I use the command line wc to optimize the memory
allocation),
load_file1 <- function(f){
## ask wc the number of words
n <- scan(textConnection(system(paste("wc -w ", f), intern=TRUE)),
what=list(integer(), character()), quiet=TRUE)[[1]]
all <- scan(f, nmax=n, quiet=TRUE)
invisible(all)
}
load_file2 <- function(f){
## ask wc...