Package 'pinyin'

Title: Convert Chinese Characters into Pinyin, Sijiao, Wubi or Other Codes
Description: Convert Chinese characters into Pinyin (the official romanization system for Standard Chinese in mainland China, Malaysia, Singapore, and Taiwan. See <https://en.wikipedia.org/wiki/Pinyin> for details), Sijiao (four or five numerical digits per character. See <https://en.wikipedia.org/wiki/Four-Corner_Method>.), Wubi (an input method with five strokes. See <https://en.wikipedia.org/wiki/Wubi_method>) or user-defined codes.
Authors: Peng Zhao [aut, cre], Qu Cheng [ctb], TC Zhang [ctb]
Maintainer: Peng Zhao <[email protected]>
License: MIT + file LICENSE
Version: 1.1.7
Built: 2024-11-17 02:53:16 UTC
Source: https://github.com/pzhaonet/pinyin

Help Index


Convert strings of Chinese characters into Pinyin.

Description

Convert strings of Chinese characters into Pinyin.

Usage

as.pinyin(char, sep = "_", other_replace = NULL, dic = pinyin::pinyin2)

Arguments

char

Requrired A input character string with chinese characters.

sep

character The seperator between the converted pinyin. Default: '_'

other_replace

character The replacement for non-Chinese characters

dic

The preloaded dictionary for conversion. Default: "pinyin::pinyin2"

Value

A character vector of the converted pinyin string.

Examples

py("hello word")

Convert the Chinese headers of bookdown .Rmd files into Pinyin

Description

Convert the Chinese headers of bookdown .Rmd files into Pinyin

Usage

bookdown2py(
  folder = "py",
  remove_curly_bracket = TRUE,
  other_replace = NULL,
  dic = NA
)

Arguments

folder

character. The folder in which the files are to be converted.

remove_curly_bracket

logical. Whether to remove existing curly brackets in the headers.

other_replace

NULL or character. Define how to convert non-Chinese characters in mychar. NULL means 'let it be'.

dic

See help(pinzin).

Value

new .Rmd files with Pinyin headers.

Examples

bookdown2py(dic = NA)

Rename files according to a given dictionary

Description

Rename files according to a given dictionary

Usage

file.rename2py(folder = "py", dic = NA)

Arguments

folder

character. The folder in which the files are to be renamed.

dic

See help(pinyin).

Value

files with new names.

Examples

file.rename2py(dic = NA)

Convert the characters in an entire files according to a given dictionary

Description

Convert the characters in an entire files according to a given dictionary

Usage

file2py(
  folder = "py",
  backup = TRUE,
  sep = " ",
  other_replace = NULL,
  encoding = "UTF-8",
  dic = NA
)

Arguments

folder

character. The folder in which the files are to be converted.

backup

logical. Whether the original files should be saved as backups.

sep

character. Seperation between the converted pinyin.

other_replace

NULL or character. Define how to convert non-Chinese characters in mychar. NULL means 'let it be'.

encoding

character. The encoding of the input files. 'UTF-8' by default.

dic

See help(pinzin).

Value

files converted to Pinyin.

Examples

file2py(dic = NA)

Title insert a character(s) before all lattin letters in a string

Description

Title insert a character(s) before all lattin letters in a string

Usage

insert(oldchar, insertchar = ",")

Arguments

oldchar

the old string

insertchar

the character(s) to insert

Value

a new string


Load a customized dictionary.

Description

Load a customized dictionary.

Usage

load_dic(dic_file = NA, select = 1)

Arguments

dic_file

The path of a dictionary file.

select

The option to choose from the dictionary.

Value

A dictionary

Examples

load_dic()

Former version of py()

Description

Former version of py()

Usage

pinyin()

Value

a message

Examples

pinyin()

The Dictionary to Convert Chinese Characters to Pinyin.

Description

A dataset containing the Chinese characters and the corresponding pinyin, Source: A friend of dapeng

Usage

pinyin2

Format

A data frame with 20520 rows and 2 variables:

key

a chinese character

value

a pinyin

...


Convert strings of Chinese characters into Pinyin.

Description

Convert strings of Chinese characters into Pinyin.

Usage

py(char = "", sep = "_", other_replace = NULL, dic = pydic())

Arguments

char

a string vector

sep

character. Seperation between the converted pinyin.

other_replace

NULL or character. Define how to convert non-Chinese characters in mychar. NULL means 'let it be'.

dic

the preloaded pinyin library using the pylib() function.

Value

pinyin of the given Chinese string.

Examples

py(dic = NA)

Convert a string of Chinese characters into Pinyin.

Description

Convert a string of Chinese characters into Pinyin.

Usage

py_single(char = "", sep = "_", other_replace = NULL, dic = pydic())

Arguments

char

character. A Chinese character or string to convert to pinyin

sep

character. Seperation between the converted pinyin.

other_replace

NULL or character. Define how to convert non-Chinese characters in mychar. NULL means 'let it be'.

dic

the preloaded pinyin library using the pylib() function.

Value

pinyin of the given Chinese string.


Load a Pinyin library

Description

Load a Pinyin library

Usage

pydic(
  method = c("quanpin", "tone", "toneless"),
  multi = FALSE,
  only_first_letter = FALSE,
  dic = c("pinyin", "pinyin2")
)

Arguments

method

character. The value can be:

  • 'quanpin', for the standard form of pinyin (tones above letters),

  • 'tone', for tones expressed with numbers,

  • 'toneless', without tones

multi

logical. Whether display multiple pronounciations of a Chinese character or only the first pronounciation.

only_first_letter

logical. Wheter only the first letter in pinyin.

dic

character. Choose the dictionary.

Value

character. a Pinyin library.

Examples

pydic()

split a string and extract the nth string

Description

split a string and extract the nth string

Usage

strsplit2(x, sep = " ", nth = 1)

Arguments

x

The string to split

sep

The separated character

nth

The nth string to extract

Value

a new string