R语言使用笔记

1. Before Install Packages

# Install tidyverse
sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev zlib1g-dev
# Install RMySQL
sudo apt-get install libmysqlclient-dev
# Install sodium/shinyauthr
sudo apt-get install libsodium-dev
# Install systemfonts 
sudo apt-get libfontconfig1-dev
# Install RODBC
sudo apt-get install unixodbc-dev
# Install postgresql
sudo apt-get install libpq-dev
# Install reticulate
sudo apt install libpng-dev

2. set repos

options(repos='http://cran.rstudio.com/')

3. edit Rprofile

file.edit(file.path("~", ".Rprofile"))

4. read_tsv with encoding and default col_types

readr::read_tsv('file',
         locale = locale(encoding = 'gbk'),
         col_types = cols(.default = 'c'))

5. shinyproxy get username

as.list(Sys.getenv())$SHINYPROXY_USERNAME

6. vscode pipe shortcut

[{
    "key": "ctrl+shift+m",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus  editorLangId == 'r'",
    "args": {
        "snippet": " |> "
    }
}]

7. fidelius

  • By rmarkdown
title: "Fidelius Config"
output: 
  fidelius::html_password_protected:
    output_format:
      rmarkdown::html_document:
        toc: true
        toc_float: true
    password: 'pw123'
    preview: false
    style:
      header_text: 'My Report'
      placeholder_text: 'plz input password'
      button_text: 'confirm'
  • By r code
library(fidelius)

charm(
  'app.rmd',
  password = '',
  style = stylize(
    header_text = 'Welcome!'
    placeholder_text = 'Enter your password',
    button_text = 'Confirm',
  ),
  output = 'app.html'
)

8. connect wps webhook

reticulate::py_run_string(r"(
def connect_wps(token,webhook):
  import http.client
  conn = http.client.HTTPSConnection("www.kdocs.cn")
  payload = "{\"Context\":{\"argv\":{}}}"
  headers = {
      'Content-Type': "application/json",
      'AirScript-Token': token
      }
  conn.request("POST", webhook, payload, headers) 
  res = conn.getresponse()
  data = res.read().decode("utf-8")
  return data
)")

reticulate::py$connect_wps(
  "token",
  "https://www.kdocs.cn/api/v3/ide/file/xx/script/xx/sync_task"
)
readWps <- function(token,webhook){
  http <- reticulate::import('http.client')
  conn = http$HTTPSConnection('www.kdocs.cn')
  payload = "{\"Context\":{\"argv\":{}}}"
  headers = 
    list(
    `Content-Type` = "application/json",
    `AirScript-Token`= token
  )
  
  conn$request('POST',
               webhook,
               payload, headers)
  res = conn$getresponse()
  dt <- jsonlite::fromJSON(
    res$read()$decode('utf-8'))$data$result$abc
  
  dt <- setNames(data.frame(dt[-1,]),dt[1,])
  return(dt)
}
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值