---
title: "tinyscholar"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{tinyscholar}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

The goal of tinyscholar is to provide a simple way to get and show Google scholar profile.

## Installation

You can install the released version of tinyscholar from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("tinyscholar")
```

And the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("ShixiangWang/tinyscholar")
# devtools::install_git("https://gitee.com/ShixiangWang/tinyscholar")
```

## Usage

Here I will use my profile as an example.

```{r}
library(tinyscholar)
```

### Get You Google Scholar ID

Firstly, you need to get your Google scholar ID from URL of your Google scholar profile or by running the following function with a keyword:

```{r, eval=FALSE}
scholar_search("Shixiang Wang")
#> Searching author Shixiang Wang
#> Using API server: https://api.scaleserp.com
#> Using Shixiang's personal API key, only 125 free searches per month for all packages users
#> Search times used: 38
#> Search times left: 87
#>             id
#> 1 FvNp0NkAAAAJ
#>                                                                                               desc
#> 1 Wang, Shixiang (王诗翔)ShanghaiTech. UniversityVerified email at shanghaitech.edu.cnCited by 127
```

Copy your ID and go to the next step.

### Get Personal Profile

Then you can use function `tinyscholar()` to get the tidy data, which is a list of two `data.frame` with added `profile` class.

```{r}
profile <- tinyscholar("FvNp0NkAAAAJ")
str(profile, max.level = 1)
```

You can use this data in your way. The following parts provide two simple ways to show the profile.

### Show Table

Table is the best way to show the scholar profile. Tinyscholar uses [gt](https://gt.rstudio.com/index.html) package to generate tables which can be easily modified.

```{r eval = inherits(profile, "ScholarProfile")}
tb <- scholar_table(profile)
tb$citations
tb$publications
```


### Show Plot

Similarly, you can show numeric data with ggplot2 package.

```{r, eval = inherits(profile, "ScholarProfile"), fig.align='center', fig.width=5, fig.height=3.5}
pl <- scholar_plot(profile)
pl$citations
pl$publications
```

## Similar R package

R package [scholar](https://cran.r-project.org/package=scholar) is a more comprehensive package to get and visualize the Google scholar profile. However, tinyscholar is lightweight and not limited in China. 
