1

I wrote a function in R, which parses arguments from a dataframe, and outputs the old dataframe + a new column with stats from each row.

I get the following warning: Warning message: In [[.data.frame(xx, sxx[j]) : named arguments other than 'exact' are discouraged

I am not sure what this means, to be honest. I did spot checks on the results and seem OK to me. The function itself is quite long, I will post it if needed to better answer the question. Edit:

This is a sample dataframe:

my_df<- data.frame('ALT'= c('A,C', 'A,G'),
                   'Sample1'= c('1/1:35,3,0,35,3,35:1:1:0:0,1,0', './.:0,0,0,0,0,0:0:0:0:0,0,0'),
                   'Sample2'= c('2/2:188,188,188,33,33,0:11:11:0:0,0,11', '1/1:255,99,0,255,99,255:33:33:0:0,33,0'),
                   'Sample3'= c('1/1:219,69,0,219,69,219:23:23:0:0,23,0', '0/1:36,0,78,48,87,120:7:3:0:4,3,0'))

And this is the function:

multi_allelic_filter_v2<- function(in_vcf, start_col, end_col, threshold=1){
  #input: must have gone through biallelic_assessment first
  table0<- in_vcf
  #ALT_alleles is the number of alt alleles with coverage > threshold across samples
  #The following function calculates coverage across samples for a single allele
  single_allele_tot_cov_count<- function(list_of_unparsed_cov,
                                         allele_pos){ 
    single_allele_coverage_count<- 0
    for (i in 1:length(list_of_unparsed_cov)) { # i is each group of coverages/sample
      single_allele_coverage_count<- single_allele_coverage_count+
        as.numeric(strsplit(as.character(list_of_unparsed_cov[i]),
                            split= ',')[[1]])[allele_pos]}
    return(single_allele_coverage_count)}
  #single row function
  #Now we need to reiterate on each ALT allele in the row
  single_row_assessment<- function(single_row){
    # No. of alternative alleles over threshold
    alt_alleles0 <- 0 
    if (single_row$is_biallelic==TRUE){
      alt_alleles0<- 1
    } else {
      alt_coverages <- numeric() #coverages across sample of each ALT allele
      altcovs_unparsed<- character() #Unparsed coverages from each sample
      for (i in start_col:end_col) {
        #Let's fill altcovs_unparsed
        altcovs_unparsed<- c(altcovs_unparsed,
                             strsplit(x = as.character(single_row[1,i]), split = ':')[[1]][6])}
      #Now let's calculate alt_coverages 
      for (i in 1:lengths(strsplit(as.character(
        single_row$ALT),',',fixed = TRUE))) {
        alt_coverages<- c(alt_coverages, single_allele_tot_cov_count(
          list_of_unparsed_cov = altcovs_unparsed, allele_pos = i+1))}
      #Now, let's see how many ALT alleles are over threshold
      alt_alleles0<- sum(alt_coverages>threshold)}
    return(alt_alleles0)}
  #Now, let's reiterate across each row:
  #ALT_alleles is no. of alt alleles with coverage >threshold across samples
  table0$ALT_alleles<- -99 # Just as a marker, to make sure function works
  for (i in 1:nrow(table0)){
    table0[i,'ALT_alleles'] <- single_row_assessment(single_row = table0[i,])}
  #Now we now how many ALT alleles >= threshold coverage are in each SNP
  return(table0)}

Basically, in the following line: '1/1:219,69,0,219,69,219:23:23:0:0,23,0' fields are separated by ":", and I am interested in the last two numbers of the last field (23 and 0); in each row I want to sum all the numbers in those positions (two separate sums), and output how many of the "sums" are over a threshold. Hope it makes sense...

Max_IT
  • 602
  • 5
  • 15
  • Sounds like you should look for someplace where inside of using `[[` you have something that looks like `foo = bar` where `foo` is not the `exact` argument. – joran Aug 11 '16 at 20:50
  • 2
    It would be much easier to help if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that generates this warning. – MrFlick Aug 11 '16 at 20:52
  • `exact` allows you to provide a vector of character names for partial matching of column names in data.frame subsetting. As per the source code, `if (!all(names(sys.call()) %in% c("", "exact"))) ` you will get this error. – shayaa Aug 11 '16 at 20:56
  • `traceback()` might be useful here. But if it's only a warning you will need to use; `options(warn=1)` – IRTFM Aug 12 '16 at 01:51
  • Thanks. I tried: traceback(options(warn=1)), but all it prints is "1:1" . Am I using it wrong? – Max_IT Aug 12 '16 at 11:55

1 Answers1

0

OK,

I re-run the script with the same dataset on the same computer (same project, then new project), then run it again on a different computer, could not get the warnings again in any case. I am not sure what happened, and the results seem correct. Never mind. Thanks anyway for the comments and advice

Max_IT
  • 602
  • 5
  • 15
  • The same happened to me with a function that I've used several times before. When I re-ran the code again later all worked fine. – Liz Feb 10 '17 at 13:21
  • Thank you. I have noticed sometimes I need to restart R, when I start getting weird errors, even with the use of published packages. Other people had similar experiences. It happens when you forget to feed the gremlins in the computer before turning it on. – Max_IT Feb 10 '17 at 19:45