Skip to content

Instantly share code, notes, and snippets.

@michaelHL
Last active June 28, 2017 13:34
Show Gist options
  • Save michaelHL/b5a97c417cf6e589dec16e30f5270608 to your computer and use it in GitHub Desktop.
Save michaelHL/b5a97c417cf6e589dec16e30f5270608 to your computer and use it in GitHub Desktop.
2017年6月折腾笔记

history 命令

  1. 可控浏览: history | less
  2. 利用环境变量 HISTTIMEFORMAT 在历史中显示 TIMEPSTAMP(时间戳):
export HISTTIMEFORMAT='%F %T '
  1. 完全清除历史消息:
history -c && history -w
  1. 利用 Ctrl + R 来搜索命令, 重复按 Ctrl + R 可向前搜索
  2. 执行之前的命令:
    • up arrowenter
    • !! enter
    • !-1 enter
    • ctrlp/n
  3. 执行指定命令: !5 (执行编号5的历史命令)
  4. 执行字符开头命令: !ps (执行以ps开头的命令)

在R中Source指定文件的指定行

代码

sources = function(file, range, eva = TRUE) {
    con = file(file, open = "r")
    lines = readLines(con)
    src = paste0(lines[unlist(range)], collapse = "\n")
    if (eva) {
        source(exprs = parse(text = src))
    } else {
        cat(src)
    }
    close(con)
}

srcline = list(10837:10841, 10843:10845)
sources("src.R", srcline)

其中 src.R 文件指定行内容如下:

test1 = function(a, b) {
    print("======test1======")
    print(paste("a + b = ", a + b, sep = ""))
    print("======test1======")
}

print("testtesttesttesttesttest")
test1(5, 4)
print("sourcesourcesourcesource")

输出

"testtesttesttesttesttest"
"======test1======"
"a + b = 9"
"======test1======"
"sourcesourcesourcesource"

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment