How to write/debug your own programs?
///////////////////////////////////////////
Step 1: generate an empty function and activate 
        myF<-function(a,b,c){

        }

Step 2: print one of the input values
        myF<-function(a,b,c){
             print(a)
        }

Step 3: one-part at a time
        myF<-function(a,b,c){
             d<- a+b+c
             print(d)
        }

Step 4: add one more part 
        myF<-function(a,b,c){
             d<- a+b+c
             print(d)
             if(d>0){
                 cat("d >0\n")
             }else{
                 cat("d <=0\n")
             }
        }

Step 5: repeat step 4 until tne end 

Case #1: why an infinite loop?
-----------------------------
    i<-1
    pv<-pv_f(fv,r,i)
    while(pv>tiny){
      # code here
      pv<-pv_f(fv,r,i)
      # other code here 
   }
   # since your conditition is pv>tiny 
///////////////////////////////////////////

How to debug others' programs?
////////////////////////////
How to debug others' complex programs?
--------------------------------------
Method I: my 'Empty-shell' Method 
         Step 1: write an empty function
         Step 2: print one of the input values
         Step 3: copy the 1st part of other's program
                 to your program and return a value
         Step 3B: if you find an error, debug it. 
         Step 4: Repeat Steps 3 and 3B for the 2nd part
                 ......
                 continue this way until you debug the whole
                 program. 

Method II: my 'Comment-all-out' Method                  
           Step 1: comment all code out
           Step 2: run the program 
           Step 3: release the first part and debug
           Step 4: repeat Step 3 many times

////////////////////////

line
////////////////////////////

Assume that we have the following two columns. 

x,y
1,6
2,9
3,12
4,15
5,17

  Step 1: highlight the above data
  Step 2: go to Excel and paste
  Step 3: If they occupy just one column, highlight this column
  Step 4: Click "Data", -> Text to column -> use comma as delimiter
  Step 5: highlight both columns
  Step 6: Click "Insert" -> Line

  [note: we will see two lines. This example is different from (x,y) 
        scatter which has one line. ]

////////////////////////////