tips and tricks

Han Oostdijk

2019/10/17

Date last run: 29Oct2019

Searching

Task Command Remark
Search in files grep -ri ‘text’ recursive and case insensitive
Search in files grep -n ‘text’ show line numbers
Search in R files grep -ri ‘trace’ --include *.R
Helpinfo for grep grep --help NB repeated - !
Find filename(s) find . -name ‘*mag2*‘ find files below current folder containing ‘mag2’ (in Terminal)

R Debugging

trace(get_trends,quote(browser()),where=asNamespace("rtweet"))
rtweet::get_trends("amsterdam")
untrace(rtweet::get_trends)

as.list(body(rtweet:::get_trends_))
trace(rtweet:::get_trends_,
			quote(browser()),
			at=8,
			where=asNamespace("rtweet"))
rtweet::get_trends("amsterdam")
untrace(rtweet:::get_trends_)

browser() commands

From browser() function help info:

Command Description
c exit the browser and continue execution at the next statement
cont synonym for c
f finish execution of the current loop or function
help print this list of commands
n evaluate the next statement, stepping over function calls. For byte compiled functions interrupted by browser calls, n is equivalent to c
s evaluate the next statement, stepping into function calls. Again, byte compiled functions make s equivalent to c
where print a stack trace of all active function calls
r invoke a “resume” restart if one is available; interpreted as an R expression otherwise. Typically “resume” restarts are established for continuing from user interrupts
Q exit the browser and the current evaluation and return to the top-level prompt

Two methods to include code with highlighting. See that the two paths are different. In the first case the base directory is the note or post directory and in the second case the base directory is the project library.

`​``{r echo=T,eval=T,comment=''}
cat(readLines("../../R/update_HOQC.R",warn=F),sep="\n")
`​``


```{r include2,code=readLines("./R/update_HOQC.R",warn=F),eval=F}
```

include code chunks in text

In the section above we showed three consecutive backticks . This is not so easy as it seems because we generated the section (in fact the whole entry) with knitr where three such backticks are ‘eaten’ after being considered to be code block delimeters. See explanation. The second block used method 1 (adding empty string) in the explanation and for the first block the second (zero-width space) method was used.

include paired asteriks (*) in text

Paired asteriks are used to italicise a phrase. When you just want to display a phrase within asteriks e.g. *italics* use the html escape code * .

include session_info chunk

Use

`​``{r child='../../local_files/session_info.Rmd'} 
`​`` 

to include the standard session_info chunk.

solution for empty line before last entry in list

After hugo version 0.57 I noticed that a list immediately followed by a code block forces an empty line between the list and its last entry. This can be solved by inserting a new line and a comment like <!-- inserted to avoid incorrect list ending -->
after the last entry.

Keyboard shortcuts

From Handboek Internetresearch & datajournalistiek and 47 Keyboard Shortcuts That Work in All Web Browsers


Ctrl+L: goto address field
Ctrl+mouse click: open the link you clicked on in an new tab
Ctrl+W: close the current tab
Ctrl+T: open a new tab
Ctrl+N: open a new window
Ctrl+Shift+N: open a new anonymous window
Ctrl+(+Shift)Tab: switch between tabs
Ctrl+R: refresh page
function F11: toggle fullscreen mode
Alt+(left/right)arrow: previous/next page
keep previous button pressed: history

Google (Groups) Common search techniques

From Common search techniques and Handboek Internetresearch & datajournalistiek :

Search social media: Put @ in front of a word to search social media. For example: @twitter
Search for a price: Put $ in front of a number. For example: camera $400
Search hashtags: Put # in front of a word. For example: #throwbackthursday
Exclude words from your search: Put - in front of a word you want to leave out. For example, jaguar speed -car
Search for an exact match: Put a word or phrase inside quotes. For example, “tallest building”
Search within a range of numbers: Put .. between two numbers. For example, camera $50..$100
Combine searches: Put “OR” between each search query. For example, marathon OR race
Search for a specific site: Put “site:” in front of a site or domain. For example, site:youtube.com or site:.gov
Search for related sites: Put “related:” in front of a web address you already know. For example, related:time.com
See Google’s cached version of a site: Put “cache:” in front of the site address
Restrict name to author (in Google Groups): Put “authorname:” in front of the name
Restrict searches: Put AND (or nothing) between each search query
Search nearby words : Put “NEAR” between two search wordse
Wildcard: Put * in search string or word