Kubke Lab:Research/ABR/Notebook/2014/01/12

From OpenWetWare
Jump to: navigation, search
Owwnotebook icon.png Hearing development in barn owls Report.pngMain project page
Resultset previous.pngPrevious entry      Next entryResultset next.png

General Entries

  • Insert content here...

Personal Entries

Fabiana

Having trouble with Knitr which seems to drop me back to the sandbox directory unless I put all the code togther - this could get annoying

rnet --> <html>


<body> <h1>Putting it all together</h1>

<p>I) Create file list from directory</p>

<p>1) Change directory to case #</p>

<pre><code class="r">

    1. For Knitr only:

setwd(&quot;~/Dropbox/OrisABR&quot;)

    1. end

print(&quot;set wd to OrisABR&quot;) </code></pre>

<pre><code>## [1] &quot;set wd to OrisABR&quot; </code></pre>

<pre><code class="r">basedir &lt;- getwd() print(basedir) </code></pre>

<pre><code>## [1] &quot;C:/Documents and Settings/mkub003.uoa/My Documents/Dropbox/OrisABR&quot; </code></pre>

<pre><code class="r">newdir &lt;- readline(&quot;enter case number: &quot;) </code></pre>

<pre><code>## enter case number: </code></pre>

<pre><code class="r">

    1. For knitr only:

newdir = &quot;owl222&quot;

    1. end


    1. create dir name as basedir\Analysis\datafiles\case:

casedir &lt;- paste(basedir, &quot;Analysis&quot;, &quot;datafiles&quot;, newdir, sep = &quot;/&quot;)

  1. dir.create(file.path(basedir, casedir), showWarnings = FALSE)

setwd(casedir) print(paste(&quot;you are now in&quot;, casedir)) </code></pre>

<pre><code>## [1] &quot;you are now in C:/Documents and Settings/mkub003.uoa/My Documents/Dropbox/OrisABR/Analysis/datafiles/owl222&quot; </code></pre>

<pre><code class="r">getwd() </code></pre>

<pre><code>## [1] &quot;C:/Documents and Settings/mkub003.uoa/My Documents/Dropbox/OrisABR/Analysis/datafiles/owl222&quot; </code></pre>

<pre><code class="r">

  1. get drectory list

files &lt;- dir() head(files) </code></pre>

<pre><code>## [1] &quot;222L01.LOG&quot; &quot;222L01.TXT&quot; &quot;222L02.LOG&quot; &quot;222L02.TXT&quot; &quot;222L03.LOG&quot;

    1. [6] &quot;222L03.TXT&quot;

</code></pre>

<pre><code class="r">

    1. subset files with log and txt
  1. need to separate the txt from the logfiles

log &lt;- regexpr(&quot;(.*)[L|l][O|o][G|g]&quot;, files) logfiles &lt;- regmatches(files, log) length(logfiles) </code></pre>

<pre><code>## [1] 16 </code></pre>

<pre><code class="r">print(logfiles) </code></pre>

<pre><code>## [1] &quot;222L01.LOG&quot; &quot;222L02.LOG&quot; &quot;222L03.LOG&quot; &quot;222L04.LOG&quot; &quot;222L05.LOG&quot;

    1. [6] &quot;222L06.LOG&quot; &quot;222L07.LOG&quot; &quot;222L08.LOG&quot; &quot;222L09.LOG&quot; &quot;222L0A.LOG&quot;
    2. [11] &quot;222L0B.LOG&quot; &quot;222L0C.LOG&quot; &quot;222L0D.LOG&quot; &quot;222L0E.LOG&quot; &quot;222R18.LOG&quot;
    3. [16] &quot;WS_FTP.LOG&quot;

</code></pre>

<pre><code class="r"> txt &lt;- regexpr(&quot;(.*)[T|t][X|x][T|t]&quot;, files) txtfiles &lt;- regmatches(files, txt) length(txtfiles) </code></pre>

<pre><code>## [1] 15 </code></pre>

<pre><code class="r">print(txtfiles) </code></pre>

<pre><code>## [1] &quot;222L01.TXT&quot; &quot;222L02.TXT&quot; &quot;222L03.TXT&quot; &quot;222L04.TXT&quot; &quot;222L05.TXT&quot;

    1. [6] &quot;222L06.TXT&quot; &quot;222L07.TXT&quot; &quot;222L08.TXT&quot; &quot;222L09.TXT&quot; &quot;222L0A.TXT&quot;
    2. [11] &quot;222L0B.TXT&quot; &quot;222L0C.TXT&quot; &quot;222L0D.TXT&quot; &quot;222L0E.TXT&quot; &quot;222R18.TXT&quot;

</code></pre>

<pre><code class="r">

  1. Need to open the text files - They are tab delimited so to get the right
  2. structure I need to #specify. Although it looks that some files are tab
  3. delimited and others are not


test &lt;- read.csv(txtfiles[1], sep = &quot;\t&quot;, header = T) dim(test) #get 1000 5 PASS </code></pre>

<pre><code>## [1] 1000 24 </code></pre>

<pre><code class="r">head(test) </code></pre>

<pre><code>## msec left right spont bin.0 bin.1 bin.2 bin.3 bin.4 bin.5 bin.6 bin.7

    1. 1 0.00 -32 -53 7 -45 -42 -8 -12 36 11 17 -33
    2. 2 0.02 -33 -66 35 -44 -26 -31 4 40 46 0 -67
    3. 3 0.04 -20 -73 75 -33 -37 -17 -10 48 38 20 -66
    4. 4 0.06 -7 -57 73 -2 -50 -4 -28 48 22 46 -68
    5. 5 0.08 6 -32 52 34 -55 -37 -34 68 8 44 -54
    6. 6 0.10 -6 -15 21 30 -29 -62 -35 42 -2 43 -51
    7. sdev_l sdev_r sdev_spont sd_bin.0 sd_bin.1 sd_bin.2 sd_bin.3 sd_bin.4
    8. 1 84 83 98 79 86 81 82 91
    9. 2 81 93 95 81 96 78 93 84
    10. 3 83 90 93 82 99 81 94 84
    11. 4 88 90 88 85 91 74 87 90
    12. 5 83 94 88 81 80 68 87 91
    13. 6 84 87 90 78 81 67 86 91
    14. sd_bin.5 sd_bin.6 sd_bin.7 X
    15. 1 86 76 81 NA
    16. 2 84 77 73 NA
    17. 3 80 78 75 NA
    18. 4 81 81 75 NA
    19. 5 82 75 76 NA
    20. 6 90 73 76 NA

</code></pre>

<p>I am thinking at this point it might actually be easier to go through all of the file stacks and have them written all in a single format so that a single function can deal with all files rather than having to create a different bit of code to deal with each peccularity. </p>

</body>

</html>

Andy

  • Enter content here

Oris

  • Enter content here