Skip to contents

This function takes a file path containing Goodreads book IDs and retrieves the rating distribution for each book.

Usage

get_rating_distribution(file_path)

Arguments

file_path

A character string specifying the path to the file containing Goodreads book IDs.

Value

A named list where each element contains the rating distribution for a book.

Examples

# \donttest{
# Create a temporary file with sample book IDs
temp_file <- tempfile(fileext = ".txt")
writeLines(c("1420", "2767052", "10210"), temp_file)

# Run the function
rating_distributions <- get_rating_distribution(temp_file)
print(rating_distributions)
#> $`1420`
#> $`1420`$`5`
#> [1] "388867"
#> 
#> $`1420`$`4`
#> [1] "339802"
#> 
#> $`1420`$`3`
#> [1] "201014"
#> 
#> $`1420`$`2`
#> [1] "54179"
#> 
#> $`1420`$`1`
#> [1] "18311"
#> 
#> 
#> $`2767052`
#> $`2767052`$`5`
#> [1] "5057310"
#> 
#> $`2767052`$`4`
#> [1] "2828222"
#> 
#> $`2767052`$`3`
#> [1] "1049057"
#> 
#> $`2767052`$`2`
#> [1] "230976"
#> 
#> $`2767052`$`1`
#> [1] "126274"
#> 
#> 
#> $`10210`
#> $`10210`$`5`
#> [1] "1035450"
#> 
#> $`10210`$`4`
#> [1] "688368"
#> 
#> $`10210`$`3`
#> [1] "339139"
#> 
#> $`10210`$`2`
#> [1] "98385"
#> 
#> $`10210`$`1`
#> [1] "53052"
#> 
#> 

# Clean up: remove the temporary file
file.remove(temp_file)
#> [1] TRUE
# }