Chapter4 R Methods and how “to`s”:
4.1 How to add Lorem ipsum paragraphs in r markdow.
lorem::ipsum() link here to see all examples.
* Quickly generate lorem ipsum placeholder text with lorem::ipsum().
* Easy to integrate in RMarkdown documents.
* Includes an RStudio addin to insert lorem ipsum into the current document.
First install
install.package("devtools")
devtools::install_github("gadenbuie/lorem")
# If devtools can not be installed.
# Install in terminal:
# brew install libgit2
#Then in R
# install.packages("devtools")
# install.packages("usethis")If error:
Error: Failed to install 'lorem' from GitHub: ERROR: failed to lock directory ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library’ for modifying **Try removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/00LOCK’**
Usage: The addin allows you to specify the number of desired paragraphs and sentences.
R Markdown
Call lorem::ipsum() in an inline R chunk in R Markdown.
`r lorem::ipsum(paragraphs = 2)` Place the scrip with “``” (inline code) to call the function. ex.
`r lorem::ipsum(paragraphs = 1)` You can control the number of paragraphs and sentences per paragraph.
`r lorem::ipsum(paragraphs = 3, sentences = c(1, 2, 3))` You can also adjust the avg_words_per_sentence to create long or short paragraphs.
`r lorem::ipsum(2, avg_words_per_sentence = 3)`
`r lorem::ipsum(1, avg_words_per_sentence = 20)` Everywhere Else
Generate lorem ipsum anywhere else using lorem::ipsum() or lorem::ipsum_words().
ipsum_items <- replicate(5, lorem::ipsum_words(5))
cat(paste("-", ipsum_items), sep = "\n")4.2 How to insert colummns in r markdown.
Description of the methods in this Link.
Put the following in the css file or directly in rmarkdown.
It is better to add directly to the style.css file for it to work properly.
<style>
.col2 {
columns: 2 200px; /* number of columns and width in pixels*/
-webkit-columns: 2 200px; /* chrome, safari */
-moz-columns: 2 200px; /* firefox */
}
.col3 {
columns: 3 100px;
-webkit-columns: 3 100px;
-moz-columns: 3 100px;
}
</style>4.2.1 3 Columns + loremipsum example
Code:
<div class="col3">
**1. paragraphs = 1**
`r lorem::ipsum()`
**2. paragraphs = 3, sentences = c(1, 2, 3)**
`r lorem::ipsum(paragraphs = 3, sentences = c(1, 2, 3))`
**3. paragraphs = 2, avg_words_per_sentence = 3**
`r lorem::ipsum(2, avg_words_per_sentence = 3)`
**4.** four.
**5.** five.
**6.** six.
**7.** seven.
**8.** eight.
**9.** nine.
</div>Result
1. paragraphs = 1
Elit pharetra nam vehicula integer dignissim himenaeos duis nam aenean quisque. Primis fermentum nunc quisque facilisi diam semper primis felis scelerisque ridiculus. Placerat malesuada vehicula hendrerit id nibh varius vulputate nec! Massa aliquam hac mollis commodo aptent facilisis aptent pharetra parturient bibendum aenean.
2. paragraphs = 3, sentences = c(1, 2, 3)
Ipsum ultrices dictum suspendisse neque dictum nullam morbi eros.
Consectetur a hendrerit dis euismod tempor magnis dictumst lacus dui fringilla. Mattis blandit litora netus eget venenatis varius eget risus eleifend vulputate!
Elit dictumst nostra lacinia lobortis gravida sed class taciti ligula habitasse natoque? Eros metus arcu eros cras metus ad morbi hendrerit magna odio duis. Eget eget dapibus gravida vestibulum natoque risus posuere aptent.
3. paragraphs = 2, avg_words_per_sentence = 3
Ipsum sociis litora morbi.
Ipsum non dignissim per in gravida nulla.
4. four.
5. five.
6. six.
7. seven.
8. eight.
9. nine.
4.2.2 2 Columns examples.
Code: (Erase the “()” in the {} section, it should be {r} only)
<div class="col2">
head(mtcars)
tail(mtcars)```
</div>Result:
head(mtcars)## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 Manual 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 Manual 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 Manual 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 Automatic 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 Automatic 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 Automatic 3 1
tail(mtcars)## mpg cyl disp hp drat wt qsec vs am gear carb
## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.7 0 Manual 5 2
## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.9 1 Manual 5 2
## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.5 0 Manual 5 4
## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.5 0 Manual 5 6
## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.6 0 Manual 5 8
## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.6 1 Manual 4 2
From here the columns are released.
4.3 How to Find the indices of lines in Markdown that are prose (not balanced).
Prose_index Find the indices of lines in Markdown that are prose (not code blocks).
Description
Filters out the indices of lines between code block fences such as ``` (could be three or four or more backticks).
Usage
library(xfun)
## ??xfun
prose_index("```", warn = TRUE)
prose_index(c("a", "```", "b", "```", "c"))
prose_index(c("a", "````", "```r", "1+1", "```", "````", "c"))Value: An integer vector of indices of lines that are prose in Markdown. Note: If the code fences are not balanced (e.g., a starting fence without an ending fence), this function will treat all lines as prose.
Still DO NOT UNDERSTAND HOW IT WORKS AND WHAT THE OUTCOME MEANS.
4.4 How to DISCHARGE git commits to avoid conflicts (Special circumstances).
Apparently it is not possible to discard changes made in >environment >Git tab. (At least I did not found a way yet).
The only way Discard is by:
- going to the GitHub desktop app,
- Select the correct repository from where to remove the changes.
- Select all the changed files (command + A)
- Right click over the selected changes.
- Select discard selected changes and click on OK.
4.5 How to create an r bookdown and link with github paages.
- Create a bookdown project in R.
// Session > New session >
// File > New project > ..[].. > New Directory > Book Project using bookdown >
// Tools > Project options (Or: // [Git] > Project Setup ) > Git/SVN > Version control System: Git >
- Open GitHub > Add > Select Project forlder in ~Documents/GitHub > Publish branch >
- Open Github in brawser > Settings > Pages > Git Pages > Source > » Master > »/docs > Saves.
In the Projects files.
README.md
R Markdown and bookdown (https://github.com/rstudio/bookdown). Bioinformatics RNA-seq project.
_bookdown.yml:
Important:
> Here is very important to add the “output_dir:”docs”.
book_filename: "Bioinformatics_RNA-seq"
delete_merged_file: true
output_dir: "docs"
language:
ui:
chapter_name: "Chapter 01"_output.yml.
bookdown::gitbook:
css: style.css
config:
toc:
before: |
<li><a href="./">Bio-Informatics</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
download: ["pdf", "epub"]Index.Rmd:
---
title: "Bioinformatics_RNA-seq"
author: "J. Marcelo Rosales R."
date: '**Created:** 2021-08-10; **Update:** 2021-08-20; **Date:** `r Sys.Date()`'
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "RNA-seq notes and trials"
---Also in Index.Rmd.
Important: To avoid the File packages.bib not found in resource path error.
Paste the following code after the md heading. knitr expects all paths to be either absolute or relative to your current R working directory.
4.6 How to change the created date or modify the date on MAC.
Resume
# To see the manual of the touch command:
man touch
# To see the metadata of the file use:
mdls Path/file # for path darg and drop file from finder to terminal
# modify creation date with touch -flag YYYYMMDDhhmm
# t for creation date, but it changes modified date
touch -t 201911252028 GH010193.MP4
touch -m 201911252028 GH010193.MP4 # Changes modified date to current date not input
touch -mt 201911252028 GH010193.MP4 # Changes modified date only, not created date
# Entire Folder
touch -t 201911252028 /*
# Only the folder (not file in folder)
touch -t 201908131200 /Volumes/homes/RosalesJM/SynDS220/Media\ Libraries/Video/GoProH7/untitled\ folder
# If folder is created for the first time, then -t flag will change both, created and modified dates
# To change created date using SetFile
man SetFile
# Changind created date of one file.
SetFile -d "11/10/2019 18:22" GH010185.MP4 # if pwd is same as files
SetFile -d "11/10/2019 18:22" /Volumes/homes/RosalesJM/SynDS220/Media\ Libraries/Video/GoProH7/GH010185.MP4 # pwd does not matter.
# Changing created date of several files at the same time.
SetFile -d "11/10/2019 18:22" GH010185.MP4 GH010186.MP4 GH010187.MP4 # etc..
SetFile -d "11/10/2019 18:44" /Volumes/HD-PCFSU3-A/Movies/VideosU/gopro\ H7/20191110-Leica\ Microscope/GH010191.MP4 /Volumes/HD-PCFSU3-A/Movies/VideosU/gopro\ H7/20191110-Leica\ Microscope/GH010192.MP4 /Volumes/homes/RosalesJM/SynDS220/Media\ Libraries/Video/GoProH7/GH010191.MP4 # etc..
# If gray-out and been used by OS
SetFile -c "" -t "" path/to/file.mov * # *: all files in the pwdVideos: https://www.youtube.com/watch?v=b33ir6FZMlY
Creation Date / Modified Date If you are changing the creation date attribute will also change the modified date attribute.
to open Terminal application (/Applications/Utilities/Terminal.app) ( cmd + space ) to open “Spotlight Search” Type in “Terminal” press enter
Explain what is for creation date and modified date -t = for created date -mt = for modified date
Replace YYYYMMDDhhmm with the desired date information:
“touch -t YYYYMMDDhhmm “ “touch -mt YYYYMMDDhhmm” ( copy without the question marks!! )
- Type the following in the command line “Do not press enter/return” !
Example: 22nd May 1986 2:24 pm ( 14:24 ) or 22.05.1986 2:24 pm
-“touch -t 198605221424 “
-“touch -mt 198605221424 “
To see the manual of the touch command:
man touch
To see the metadata of the file use:
mdls Path/file
touch -t is used to change the modification date now onwards
Do not forget the space otherwise you get a message ( touch: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] )
- Open Finder locate the file you wish to modify. Drag and drop the file into the Terminal window, the file, and path will be added to the end of the line.
Here is an example of what the line should look like:
Option 1: Single file touch -t 198605221424 /Users/maikkleinert/Desktop/How to modify date or time/all in one pdf_by_MaikKleinert.com.pdf
Option 2: Multiple file touch -t 198605221424 /Users/maikkleinert/Desktop/How to modify date or time/Concert-Online-Course_by_MaikKleinert.com.jpg /Users/maikkleinert/Desktop/How to modify date or time/Film Photo Collective_by_MaikKleinert.com.png /Users/maikkleinert/Desktop/How to modify date or time/Instagram (MaikKleinert.png?)
Option 3: Folder ( Do not forget the /) touch -t 198605221424 /Users/maikkleinert/Desktop/How to modify date or time FOLDER /
Then press enter! Done
To check the date ( right click on file and “Get Info” ) or press ( cmd+I )
Also you can Add /* to the end of the command. If you’re only targeting a specific file type include its extension (e.g. /.jpg). Example: touch -t 198605221424 /Users/maikkleinert/Desktop/How to modify date or time FOLDER/.jpgor touch -t 198605221424 /Users/maikkleinert/Desktop/How to modify date or time FOLDER/*.pdf
4.6.1 Update
If It’s not working then try this out creation date: (angle Bracket right) Setfile -d ‘08/31/2019 11:00:00’ (angle bracket left)file.txt(angle Bracket right)
SetFile -d ‘MM/DD/YYYY’ drag and drop file here (changing Creation date of file)
EXAMPLES
This command line sets the creation date of all .MP4 files in the “present” folder” (first go to the folder were the files are located with cd path/to/folderthen type:
SetFile -d "05/25/2021 10:00" *.MP4
This command line sets the modification date of “myFile”:
SetFile -m "8/4/2001 16:13" myFile
If file in external HD, greyed out and won’t open: “this item is used by Mac OS X” The file won’t open, with QuickTime, with the following error message:
Item “file.mov” is used by Mac OS X and cannot be opened. This is a common issue which happens when the file’s type and creator attributes are modified by Finder when its writing files, if these attributes aren’t restored back to the original values by Finder at the end of its write action, those files won’t be accessible to the user.
Running this command will remove the creator and type attributes set by Finder,
SetFile -c “” -t “” path/to/file.mov Note: If the above command is not found, try installing Xcode command line tool and try the above command again,
4.7 How to copy all files with a certain extension from all subdirectories
# Go to the folder containing the subfolders and files.
cd /Volumes/1TBRedBuffal/new\ vids/DVF/HDVF
# Copy all the files with extension M2T
cp **/*.M2T /Volumes/homes/RosalesJM/SynDS220/Media\ Libraries/Video/20211014-ProArch_IG/Raw-M2TOption 1:
find . -name \*.xls -exec cp {} newDir \;
in which cp is executed for each filename that find finds, and passed the filename correctly. Here’s more info on this technique.
Option 2:
Instead of all the above, you could use zsh and simply type
cp **/*.xls target_directory
zsh can expand wildcards to include subdirectories and makes this sort of thing very easy.