[R] Why do return or visible don´t return my objekt?

Christoph Heibl christoph.heibl at gmx.net
Fri Jan 26 20:23:26 CET 2007


Dear RRRRRrrrrrrrrlist!

I´ve got two lists which contain sets of DNA-sequences. They look  
something like this:

	List of 33
	$ Cunonia_atrorubens                 : chr [1:247] "t" "t" "n" "t" ...
	$ Cunonia_balansae                   : chr [1:254] "t" "c" "c" "c" ...
	$ Cunonia_capensis                   : chr [1:236] "v" "t" "c" "c" ...
	$ Cunonia_macrophylla                : chr [1:236] "t" "t" "a" "t" ...
	$ Pancheria_engleriana               : chr [1:315] "c" "t" "c" "c" ...
	[....]
	$ Brunellia_colombiana               : chr [1:336] "t" "t" "c" "t" ...
	$ Brunellia_oliveri                  : chr [1:368] "t" "a" "a" "t" ...
	$ Bauera_rubioides                   : chr [1:276] "t" "c" "t" "c" ...
	$ Bauera_sessiliflora                : chr [1:332] "t" "c" "t" "c" ...
	$ Davidsonia_pruriens_var._jeryseyana: chr [1:300] "t" "t" "c" "t" ...
	$ Davidsonia_sp._'johnsonii'         : chr [1:268] "c" "c" "c" "t" ...
	- attr(*, "species")= chr [1:33] "Cunonia_atrorubens"  
"Cunonia_balansae" "Cunonia_capensis" "Cunonia_macrophylla" ...


The names of each entry in first list match exactly the names of the  
entries in the second list and both list contain the same number of  
sequences (although not of the same length)
I want to concatenate these sequences by the following function:

	interleave <- function(seq1, seq2)
	{
		#create a list to contain concatenated sequences
		sequence <- list()			
		for (name in names(seq1)) 	# get names as indices
			{
			# concatenate sequences
			sequence[[name]] <- c(seq1[[name]], seq2[[name]])
			}
	# return concatenated sequences
	invisible(sequence)	
	}

I guess the function works in principle, because they commands do so  
if I enter them step by step.
But when I call the function it does not return my object "sequence".  
But why?
(This happened to me with some functions that I wrote, but not all.  
The error seems quite erratic : ) to me and I can´t figure out what  
to change)

Thanks a lot in advance!

Christoph



More information about the R-help mailing list