Here, I key in the data and then create a dataframe.
# Create the data frame
mart_data <- tibble::tribble(
~Category, ~Item_Name, ~Item_ID, ~Brand, ~Price, ~Variation_ID, ~Variation_Details,
"Electronics", "Smartphone", 101, "TechBrand", 699.99, "101-A", "Color: Black, Storage: 64GB",
"Electronics", "Smartphone", 101, "TechBrand", 699.99, "101-B", "Color: White, Storage: 128GB",
"Electronics", "Laptop", 102, "CompuBrand", 1099.99, "102-A", "Color: Silver, Storage: 256GB",
"Electronics", "Laptop", 102, "CompuBrand", 1099.99, "102-B", "Color: Space Gray, Storage: 512GB",
"Home Appliances", "Refrigerator", 201, "HomeCool", 899.99, "201-A", "Color: Stainless Steel, Capacity: 20 cu ft",
"Home Appliances", "Refrigerator", 201, "HomeCool", 899.99, "201-B", "Color: White, Capacity: 18 cu ft",
"Home Appliances", "Washing Machine", 202, "CleanTech", 499.99, "202-A", "Type: Front Load, Capacity: 4.5 cu ft",
"Home Appliances", "Washing Machine", 202, "CleanTech", 499.99, "202-B", "Type: Top Load, Capacity: 5.0 cu ft",
"Clothing", "T-Shirt", 301, "FashionCo", 19.99, "301-A", "Color: Blue, Size: S",
"Clothing", "T-Shirt", 301, "FashionCo", 19.99, "301-B", "Color: Red, Size: M",
"Clothing", "T-Shirt", 301, "FashionCo", 19.99, "301-C", "Color: Green, Size: L",
"Clothing", "Jeans", 302, "DenimWorks", 49.99, "302-A", "Color: Dark Blue, Size: 32",
"Clothing", "Jeans", 302, "DenimWorks", 49.99, "302-B", "Color: Light Blue, Size: 34",
"Books", "Fiction Novel", 401, "-", 14.99, "401-A", "Format: Hardcover, Language: English",
"Books", "Fiction Novel", 401, "-", 14.99, "401-B", "Format: Paperback, Language: Spanish",
"Books", "Non-Fiction Guide", 402, "-", 24.99, "402-A", "Format: eBook, Language: English",
"Books", "Non-Fiction Guide", 402, "-", 24.99, "402-B", "Format: Paperback, Language: French",
"Sports Equipment", "Basketball", 501, "SportsGear", 29.99, "501-A", "Size: Size 7, Color: Orange",
"Sports Equipment", "Tennis Racket", 502, "RacketPro", 89.99, "502-A", "Material: Graphite, Color: Black",
"Sports Equipment", "Tennis Racket", 502, "RacketPro", 89.99, "502-B", "Material: Aluminum, Color: Silver"
)
print(mart_data)## # A tibble: 20 × 7
## Category Item_Name Item_ID Brand Price Variation_ID Variation_Details
## <chr> <chr> <dbl> <chr> <dbl> <chr> <chr>
## 1 Electronics Smartpho… 101 Tech… 700. 101-A Color: Black, St…
## 2 Electronics Smartpho… 101 Tech… 700. 101-B Color: White, St…
## 3 Electronics Laptop 102 Comp… 1100. 102-A Color: Silver, S…
## 4 Electronics Laptop 102 Comp… 1100. 102-B Color: Space Gra…
## 5 Home Appliances Refriger… 201 Home… 900. 201-A Color: Stainless…
## 6 Home Appliances Refriger… 201 Home… 900. 201-B Color: White, Ca…
## 7 Home Appliances Washing … 202 Clea… 500. 202-A Type: Front Load…
## 8 Home Appliances Washing … 202 Clea… 500. 202-B Type: Top Load, …
## 9 Clothing T-Shirt 301 Fash… 20.0 301-A Color: Blue, Siz…
## 10 Clothing T-Shirt 301 Fash… 20.0 301-B Color: Red, Size…
## 11 Clothing T-Shirt 301 Fash… 20.0 301-C Color: Green, Si…
## 12 Clothing Jeans 302 Deni… 50.0 302-A Color: Dark Blue…
## 13 Clothing Jeans 302 Deni… 50.0 302-B Color: Light Blu…
## 14 Books Fiction … 401 - 15.0 401-A Format: Hardcove…
## 15 Books Fiction … 401 - 15.0 401-B Format: Paperbac…
## 16 Books Non-Fict… 402 - 25.0 402-A Format: eBook, L…
## 17 Books Non-Fict… 402 - 25.0 402-B Format: Paperbac…
## 18 Sports Equipme… Basketba… 501 Spor… 30.0 501-A Size: Size 7, Co…
## 19 Sports Equipme… Tennis R… 502 Rack… 90.0 502-A Material: Graphi…
## 20 Sports Equipme… Tennis R… 502 Rack… 90.0 502-B Material: Alumin…
## [
## {
## "Category": "Electronics",
## "Item_Name": "Smartphone",
## "Item_ID": 101,
## "Brand": "TechBrand",
## "Price": 699.99,
## "Variation_ID": "101-A",
## "Variation_Details": "Color: Black, Storage: 64GB"
## },
## {
## "Category": "Electronics",
## "Item_Name": "Smartphone",
## "Item_ID": 101,
## "Brand": "TechBrand",
## "Price": 699.99,
## "Variation_ID": "101-B",
## "Variation_Details": "Color: White, Storage: 128GB"
## },
## {
## "Category": "Electronics",
## "Item_Name": "Laptop",
## "Item_ID": 102,
## "Brand": "CompuBrand",
## "Price": 1099.99,
## "Variation_ID": "102-A",
## "Variation_Details": "Color: Silver, Storage: 256GB"
## },
## {
## "Category": "Electronics",
## "Item_Name": "Laptop",
## "Item_ID": 102,
## "Brand": "CompuBrand",
## "Price": 1099.99,
## "Variation_ID": "102-B",
## "Variation_Details": "Color: Space Gray, Storage: 512GB"
## },
## {
## "Category": "Home Appliances",
## "Item_Name": "Refrigerator",
## "Item_ID": 201,
## "Brand": "HomeCool",
## "Price": 899.99,
## "Variation_ID": "201-A",
## "Variation_Details": "Color: Stainless Steel, Capacity: 20 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item_Name": "Refrigerator",
## "Item_ID": 201,
## "Brand": "HomeCool",
## "Price": 899.99,
## "Variation_ID": "201-B",
## "Variation_Details": "Color: White, Capacity: 18 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item_Name": "Washing Machine",
## "Item_ID": 202,
## "Brand": "CleanTech",
## "Price": 499.99,
## "Variation_ID": "202-A",
## "Variation_Details": "Type: Front Load, Capacity: 4.5 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item_Name": "Washing Machine",
## "Item_ID": 202,
## "Brand": "CleanTech",
## "Price": 499.99,
## "Variation_ID": "202-B",
## "Variation_Details": "Type: Top Load, Capacity: 5.0 cu ft"
## },
## {
## "Category": "Clothing",
## "Item_Name": "T-Shirt",
## "Item_ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation_ID": "301-A",
## "Variation_Details": "Color: Blue, Size: S"
## },
## {
## "Category": "Clothing",
## "Item_Name": "T-Shirt",
## "Item_ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation_ID": "301-B",
## "Variation_Details": "Color: Red, Size: M"
## },
## {
## "Category": "Clothing",
## "Item_Name": "T-Shirt",
## "Item_ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation_ID": "301-C",
## "Variation_Details": "Color: Green, Size: L"
## },
## {
## "Category": "Clothing",
## "Item_Name": "Jeans",
## "Item_ID": 302,
## "Brand": "DenimWorks",
## "Price": 49.99,
## "Variation_ID": "302-A",
## "Variation_Details": "Color: Dark Blue, Size: 32"
## },
## {
## "Category": "Clothing",
## "Item_Name": "Jeans",
## "Item_ID": 302,
## "Brand": "DenimWorks",
## "Price": 49.99,
## "Variation_ID": "302-B",
## "Variation_Details": "Color: Light Blue, Size: 34"
## },
## {
## "Category": "Books",
## "Item_Name": "Fiction Novel",
## "Item_ID": 401,
## "Brand": "-",
## "Price": 14.99,
## "Variation_ID": "401-A",
## "Variation_Details": "Format: Hardcover, Language: English"
## },
## {
## "Category": "Books",
## "Item_Name": "Fiction Novel",
## "Item_ID": 401,
## "Brand": "-",
## "Price": 14.99,
## "Variation_ID": "401-B",
## "Variation_Details": "Format: Paperback, Language: Spanish"
## },
## {
## "Category": "Books",
## "Item_Name": "Non-Fiction Guide",
## "Item_ID": 402,
## "Brand": "-",
## "Price": 24.99,
## "Variation_ID": "402-A",
## "Variation_Details": "Format: eBook, Language: English"
## },
## {
## "Category": "Books",
## "Item_Name": "Non-Fiction Guide",
## "Item_ID": 402,
## "Brand": "-",
## "Price": 24.99,
## "Variation_ID": "402-B",
## "Variation_Details": "Format: Paperback, Language: French"
## },
## {
## "Category": "Sports Equipment",
## "Item_Name": "Basketball",
## "Item_ID": 501,
## "Brand": "SportsGear",
## "Price": 29.99,
## "Variation_ID": "501-A",
## "Variation_Details": "Size: Size 7, Color: Orange"
## },
## {
## "Category": "Sports Equipment",
## "Item_Name": "Tennis Racket",
## "Item_ID": 502,
## "Brand": "RacketPro",
## "Price": 89.99,
## "Variation_ID": "502-A",
## "Variation_Details": "Material: Graphite, Color: Black"
## },
## {
## "Category": "Sports Equipment",
## "Item_Name": "Tennis Racket",
## "Item_ID": 502,
## "Brand": "RacketPro",
## "Price": 89.99,
## "Variation_ID": "502-B",
## "Variation_Details": "Material: Aluminum, Color: Silver"
## }
## ]
write(json_mart_data, file = "json_data_file.json")
# Reading JSON back into R
json_mart_datafile <- fromJSON("C:\\Users\\HP\\Documents\\R projects\\Week 7\\json_data_file.json")
print(json_mart_datafile)## Category Item_Name Item_ID Brand Price Variation_ID
## 1 Electronics Smartphone 101 TechBrand 699.99 101-A
## 2 Electronics Smartphone 101 TechBrand 699.99 101-B
## 3 Electronics Laptop 102 CompuBrand 1099.99 102-A
## 4 Electronics Laptop 102 CompuBrand 1099.99 102-B
## 5 Home Appliances Refrigerator 201 HomeCool 899.99 201-A
## 6 Home Appliances Refrigerator 201 HomeCool 899.99 201-B
## 7 Home Appliances Washing Machine 202 CleanTech 499.99 202-A
## 8 Home Appliances Washing Machine 202 CleanTech 499.99 202-B
## 9 Clothing T-Shirt 301 FashionCo 19.99 301-A
## 10 Clothing T-Shirt 301 FashionCo 19.99 301-B
## 11 Clothing T-Shirt 301 FashionCo 19.99 301-C
## 12 Clothing Jeans 302 DenimWorks 49.99 302-A
## 13 Clothing Jeans 302 DenimWorks 49.99 302-B
## 14 Books Fiction Novel 401 - 14.99 401-A
## 15 Books Fiction Novel 401 - 14.99 401-B
## 16 Books Non-Fiction Guide 402 - 24.99 402-A
## 17 Books Non-Fiction Guide 402 - 24.99 402-B
## 18 Sports Equipment Basketball 501 SportsGear 29.99 501-A
## 19 Sports Equipment Tennis Racket 502 RacketPro 89.99 502-A
## 20 Sports Equipment Tennis Racket 502 RacketPro 89.99 502-B
## Variation_Details
## 1 Color: Black, Storage: 64GB
## 2 Color: White, Storage: 128GB
## 3 Color: Silver, Storage: 256GB
## 4 Color: Space Gray, Storage: 512GB
## 5 Color: Stainless Steel, Capacity: 20 cu ft
## 6 Color: White, Capacity: 18 cu ft
## 7 Type: Front Load, Capacity: 4.5 cu ft
## 8 Type: Top Load, Capacity: 5.0 cu ft
## 9 Color: Blue, Size: S
## 10 Color: Red, Size: M
## 11 Color: Green, Size: L
## 12 Color: Dark Blue, Size: 32
## 13 Color: Light Blue, Size: 34
## 14 Format: Hardcover, Language: English
## 15 Format: Paperback, Language: Spanish
## 16 Format: eBook, Language: English
## 17 Format: Paperback, Language: French
## 18 Size: Size 7, Color: Orange
## 19 Material: Graphite, Color: Black
## 20 Material: Aluminum, Color: Silver
# Convert to HTML
html_data <- htmlTable::htmlTable(mart_data)
write(html_data, file = "html_data_file.html")
cat(html_data)## <table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
## <thead>
## <tr><th style='border-bottom: 1px solid grey; border-top: 2px solid grey;'></th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Category</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Item_Name</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Item_ID</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Brand</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Price</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Variation_ID</th>
## <th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: center;'>Variation_Details</th>
## </tr>
## </thead>
## <tbody>
## <tr>
## <td style='text-align: left;'>1</td>
## <td style='text-align: center;'>Electronics</td>
## <td style='text-align: center;'>Smartphone</td>
## <td style='text-align: center;'>101</td>
## <td style='text-align: center;'>TechBrand</td>
## <td style='text-align: center;'>699.99</td>
## <td style='text-align: center;'>101-A</td>
## <td style='text-align: center;'>Color: Black, Storage: 64GB</td>
## </tr>
## <tr>
## <td style='text-align: left;'>2</td>
## <td style='text-align: center;'>Electronics</td>
## <td style='text-align: center;'>Smartphone</td>
## <td style='text-align: center;'>101</td>
## <td style='text-align: center;'>TechBrand</td>
## <td style='text-align: center;'>699.99</td>
## <td style='text-align: center;'>101-B</td>
## <td style='text-align: center;'>Color: White, Storage: 128GB</td>
## </tr>
## <tr>
## <td style='text-align: left;'>3</td>
## <td style='text-align: center;'>Electronics</td>
## <td style='text-align: center;'>Laptop</td>
## <td style='text-align: center;'>102</td>
## <td style='text-align: center;'>CompuBrand</td>
## <td style='text-align: center;'>1099.99</td>
## <td style='text-align: center;'>102-A</td>
## <td style='text-align: center;'>Color: Silver, Storage: 256GB</td>
## </tr>
## <tr>
## <td style='text-align: left;'>4</td>
## <td style='text-align: center;'>Electronics</td>
## <td style='text-align: center;'>Laptop</td>
## <td style='text-align: center;'>102</td>
## <td style='text-align: center;'>CompuBrand</td>
## <td style='text-align: center;'>1099.99</td>
## <td style='text-align: center;'>102-B</td>
## <td style='text-align: center;'>Color: Space Gray, Storage: 512GB</td>
## </tr>
## <tr>
## <td style='text-align: left;'>5</td>
## <td style='text-align: center;'>Home Appliances</td>
## <td style='text-align: center;'>Refrigerator</td>
## <td style='text-align: center;'>201</td>
## <td style='text-align: center;'>HomeCool</td>
## <td style='text-align: center;'>899.99</td>
## <td style='text-align: center;'>201-A</td>
## <td style='text-align: center;'>Color: Stainless Steel, Capacity: 20 cu ft</td>
## </tr>
## <tr>
## <td style='text-align: left;'>6</td>
## <td style='text-align: center;'>Home Appliances</td>
## <td style='text-align: center;'>Refrigerator</td>
## <td style='text-align: center;'>201</td>
## <td style='text-align: center;'>HomeCool</td>
## <td style='text-align: center;'>899.99</td>
## <td style='text-align: center;'>201-B</td>
## <td style='text-align: center;'>Color: White, Capacity: 18 cu ft</td>
## </tr>
## <tr>
## <td style='text-align: left;'>7</td>
## <td style='text-align: center;'>Home Appliances</td>
## <td style='text-align: center;'>Washing Machine</td>
## <td style='text-align: center;'>202</td>
## <td style='text-align: center;'>CleanTech</td>
## <td style='text-align: center;'>499.99</td>
## <td style='text-align: center;'>202-A</td>
## <td style='text-align: center;'>Type: Front Load, Capacity: 4.5 cu ft</td>
## </tr>
## <tr>
## <td style='text-align: left;'>8</td>
## <td style='text-align: center;'>Home Appliances</td>
## <td style='text-align: center;'>Washing Machine</td>
## <td style='text-align: center;'>202</td>
## <td style='text-align: center;'>CleanTech</td>
## <td style='text-align: center;'>499.99</td>
## <td style='text-align: center;'>202-B</td>
## <td style='text-align: center;'>Type: Top Load, Capacity: 5.0 cu ft</td>
## </tr>
## <tr>
## <td style='text-align: left;'>9</td>
## <td style='text-align: center;'>Clothing</td>
## <td style='text-align: center;'>T-Shirt</td>
## <td style='text-align: center;'>301</td>
## <td style='text-align: center;'>FashionCo</td>
## <td style='text-align: center;'>19.99</td>
## <td style='text-align: center;'>301-A</td>
## <td style='text-align: center;'>Color: Blue, Size: S</td>
## </tr>
## <tr>
## <td style='text-align: left;'>10</td>
## <td style='text-align: center;'>Clothing</td>
## <td style='text-align: center;'>T-Shirt</td>
## <td style='text-align: center;'>301</td>
## <td style='text-align: center;'>FashionCo</td>
## <td style='text-align: center;'>19.99</td>
## <td style='text-align: center;'>301-B</td>
## <td style='text-align: center;'>Color: Red, Size: M</td>
## </tr>
## <tr>
## <td style='text-align: left;'>11</td>
## <td style='text-align: center;'>Clothing</td>
## <td style='text-align: center;'>T-Shirt</td>
## <td style='text-align: center;'>301</td>
## <td style='text-align: center;'>FashionCo</td>
## <td style='text-align: center;'>19.99</td>
## <td style='text-align: center;'>301-C</td>
## <td style='text-align: center;'>Color: Green, Size: L</td>
## </tr>
## <tr>
## <td style='text-align: left;'>12</td>
## <td style='text-align: center;'>Clothing</td>
## <td style='text-align: center;'>Jeans</td>
## <td style='text-align: center;'>302</td>
## <td style='text-align: center;'>DenimWorks</td>
## <td style='text-align: center;'>49.99</td>
## <td style='text-align: center;'>302-A</td>
## <td style='text-align: center;'>Color: Dark Blue, Size: 32</td>
## </tr>
## <tr>
## <td style='text-align: left;'>13</td>
## <td style='text-align: center;'>Clothing</td>
## <td style='text-align: center;'>Jeans</td>
## <td style='text-align: center;'>302</td>
## <td style='text-align: center;'>DenimWorks</td>
## <td style='text-align: center;'>49.99</td>
## <td style='text-align: center;'>302-B</td>
## <td style='text-align: center;'>Color: Light Blue, Size: 34</td>
## </tr>
## <tr>
## <td style='text-align: left;'>14</td>
## <td style='text-align: center;'>Books</td>
## <td style='text-align: center;'>Fiction Novel</td>
## <td style='text-align: center;'>401</td>
## <td style='text-align: center;'>-</td>
## <td style='text-align: center;'>14.99</td>
## <td style='text-align: center;'>401-A</td>
## <td style='text-align: center;'>Format: Hardcover, Language: English</td>
## </tr>
## <tr>
## <td style='text-align: left;'>15</td>
## <td style='text-align: center;'>Books</td>
## <td style='text-align: center;'>Fiction Novel</td>
## <td style='text-align: center;'>401</td>
## <td style='text-align: center;'>-</td>
## <td style='text-align: center;'>14.99</td>
## <td style='text-align: center;'>401-B</td>
## <td style='text-align: center;'>Format: Paperback, Language: Spanish</td>
## </tr>
## <tr>
## <td style='text-align: left;'>16</td>
## <td style='text-align: center;'>Books</td>
## <td style='text-align: center;'>Non-Fiction Guide</td>
## <td style='text-align: center;'>402</td>
## <td style='text-align: center;'>-</td>
## <td style='text-align: center;'>24.99</td>
## <td style='text-align: center;'>402-A</td>
## <td style='text-align: center;'>Format: eBook, Language: English</td>
## </tr>
## <tr>
## <td style='text-align: left;'>17</td>
## <td style='text-align: center;'>Books</td>
## <td style='text-align: center;'>Non-Fiction Guide</td>
## <td style='text-align: center;'>402</td>
## <td style='text-align: center;'>-</td>
## <td style='text-align: center;'>24.99</td>
## <td style='text-align: center;'>402-B</td>
## <td style='text-align: center;'>Format: Paperback, Language: French</td>
## </tr>
## <tr>
## <td style='text-align: left;'>18</td>
## <td style='text-align: center;'>Sports Equipment</td>
## <td style='text-align: center;'>Basketball</td>
## <td style='text-align: center;'>501</td>
## <td style='text-align: center;'>SportsGear</td>
## <td style='text-align: center;'>29.99</td>
## <td style='text-align: center;'>501-A</td>
## <td style='text-align: center;'>Size: Size 7, Color: Orange</td>
## </tr>
## <tr>
## <td style='text-align: left;'>19</td>
## <td style='text-align: center;'>Sports Equipment</td>
## <td style='text-align: center;'>Tennis Racket</td>
## <td style='text-align: center;'>502</td>
## <td style='text-align: center;'>RacketPro</td>
## <td style='text-align: center;'>89.99</td>
## <td style='text-align: center;'>502-A</td>
## <td style='text-align: center;'>Material: Graphite, Color: Black</td>
## </tr>
## <tr>
## <td style='border-bottom: 2px solid grey; text-align: left;'>20</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>Sports Equipment</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>Tennis Racket</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>502</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>RacketPro</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>89.99</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>502-B</td>
## <td style='border-bottom: 2px solid grey; text-align: center;'>Material: Aluminum, Color: Silver</td>
## </tr>
## </tbody>
## </table>
# Read HTML back into R
library(rvest)
html_content <- read_html("html_data_file.html")
imported_html_data <- html_content %>% html_table(fill = TRUE) %>% .[[1]]
print(imported_html_data)## # A tibble: 20 × 8
## `` Category Item_Name Item_ID Brand Price Variation_ID Variation_Details
## <int> <chr> <chr> <int> <chr> <dbl> <chr> <chr>
## 1 1 Electron… Smartpho… 101 Tech… 700. 101-A Color: Black, St…
## 2 2 Electron… Smartpho… 101 Tech… 700. 101-B Color: White, St…
## 3 3 Electron… Laptop 102 Comp… 1100. 102-A Color: Silver, S…
## 4 4 Electron… Laptop 102 Comp… 1100. 102-B Color: Space Gra…
## 5 5 Home App… Refriger… 201 Home… 900. 201-A Color: Stainless…
## 6 6 Home App… Refriger… 201 Home… 900. 201-B Color: White, Ca…
## 7 7 Home App… Washing … 202 Clea… 500. 202-A Type: Front Load…
## 8 8 Home App… Washing … 202 Clea… 500. 202-B Type: Top Load, …
## 9 9 Clothing T-Shirt 301 Fash… 20.0 301-A Color: Blue, Siz…
## 10 10 Clothing T-Shirt 301 Fash… 20.0 301-B Color: Red, Size…
## 11 11 Clothing T-Shirt 301 Fash… 20.0 301-C Color: Green, Si…
## 12 12 Clothing Jeans 302 Deni… 50.0 302-A Color: Dark Blue…
## 13 13 Clothing Jeans 302 Deni… 50.0 302-B Color: Light Blu…
## 14 14 Books Fiction … 401 - 15.0 401-A Format: Hardcove…
## 15 15 Books Fiction … 401 - 15.0 401-B Format: Paperbac…
## 16 16 Books Non-Fict… 402 - 25.0 402-A Format: eBook, L…
## 17 17 Books Non-Fict… 402 - 25.0 402-B Format: Paperbac…
## 18 18 Sports E… Basketba… 501 Spor… 30.0 501-A Size: Size 7, Co…
## 19 19 Sports E… Tennis R… 502 Rack… 90.0 502-A Material: Graphi…
## 20 20 Sports E… Tennis R… 502 Rack… 90.0 502-B Material: Alumin…
# Convert to XML
xml_data <- XML::newXMLNode("Inventory")
for (i in 1:nrow(mart_data)) {
item <- XML::newXMLNode("Item", parent = xml_data)
for (j in 1:ncol(mart_data)) {
XML::newXMLNode(names(mart_data)[j], mart_data[i, j], parent = item)
}
}## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## Warning in removeNodes.list(kids[!vapply(kids, is.character, logical(1L))]):
## removeNode only works on internal nodes at present
## [1] "xml_data_file.xml"
## <Inventory>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Smartphone</Item_Name>
## <Item_ID>101</Item_ID>
## <Brand>TechBrand</Brand>
## <Price>699.99</Price>
## <Variation_ID>101-A</Variation_ID>
## <Variation_Details>Color: Black, Storage: 64GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Smartphone</Item_Name>
## <Item_ID>101</Item_ID>
## <Brand>TechBrand</Brand>
## <Price>699.99</Price>
## <Variation_ID>101-B</Variation_ID>
## <Variation_Details>Color: White, Storage: 128GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Laptop</Item_Name>
## <Item_ID>102</Item_ID>
## <Brand>CompuBrand</Brand>
## <Price>1099.99</Price>
## <Variation_ID>102-A</Variation_ID>
## <Variation_Details>Color: Silver, Storage: 256GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Laptop</Item_Name>
## <Item_ID>102</Item_ID>
## <Brand>CompuBrand</Brand>
## <Price>1099.99</Price>
## <Variation_ID>102-B</Variation_ID>
## <Variation_Details>Color: Space Gray, Storage: 512GB</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Refrigerator</Item_Name>
## <Item_ID>201</Item_ID>
## <Brand>HomeCool</Brand>
## <Price>899.99</Price>
## <Variation_ID>201-A</Variation_ID>
## <Variation_Details>Color: Stainless Steel, Capacity: 20 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Refrigerator</Item_Name>
## <Item_ID>201</Item_ID>
## <Brand>HomeCool</Brand>
## <Price>899.99</Price>
## <Variation_ID>201-B</Variation_ID>
## <Variation_Details>Color: White, Capacity: 18 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Washing Machine</Item_Name>
## <Item_ID>202</Item_ID>
## <Brand>CleanTech</Brand>
## <Price>499.99</Price>
## <Variation_ID>202-A</Variation_ID>
## <Variation_Details>Type: Front Load, Capacity: 4.5 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Washing Machine</Item_Name>
## <Item_ID>202</Item_ID>
## <Brand>CleanTech</Brand>
## <Price>499.99</Price>
## <Variation_ID>202-B</Variation_ID>
## <Variation_Details>Type: Top Load, Capacity: 5.0 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-A</Variation_ID>
## <Variation_Details>Color: Blue, Size: S</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-B</Variation_ID>
## <Variation_Details>Color: Red, Size: M</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-C</Variation_ID>
## <Variation_Details>Color: Green, Size: L</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>Jeans</Item_Name>
## <Item_ID>302</Item_ID>
## <Brand>DenimWorks</Brand>
## <Price>49.99</Price>
## <Variation_ID>302-A</Variation_ID>
## <Variation_Details>Color: Dark Blue, Size: 32</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>Jeans</Item_Name>
## <Item_ID>302</Item_ID>
## <Brand>DenimWorks</Brand>
## <Price>49.99</Price>
## <Variation_ID>302-B</Variation_ID>
## <Variation_Details>Color: Light Blue, Size: 34</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Fiction Novel</Item_Name>
## <Item_ID>401</Item_ID>
## <Brand>-</Brand>
## <Price>14.99</Price>
## <Variation_ID>401-A</Variation_ID>
## <Variation_Details>Format: Hardcover, Language: English</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Fiction Novel</Item_Name>
## <Item_ID>401</Item_ID>
## <Brand>-</Brand>
## <Price>14.99</Price>
## <Variation_ID>401-B</Variation_ID>
## <Variation_Details>Format: Paperback, Language: Spanish</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Non-Fiction Guide</Item_Name>
## <Item_ID>402</Item_ID>
## <Brand>-</Brand>
## <Price>24.99</Price>
## <Variation_ID>402-A</Variation_ID>
## <Variation_Details>Format: eBook, Language: English</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Non-Fiction Guide</Item_Name>
## <Item_ID>402</Item_ID>
## <Brand>-</Brand>
## <Price>24.99</Price>
## <Variation_ID>402-B</Variation_ID>
## <Variation_Details>Format: Paperback, Language: French</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Basketball</Item_Name>
## <Item_ID>501</Item_ID>
## <Brand>SportsGear</Brand>
## <Price>29.99</Price>
## <Variation_ID>501-A</Variation_ID>
## <Variation_Details>Size: Size 7, Color: Orange</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Tennis Racket</Item_Name>
## <Item_ID>502</Item_ID>
## <Brand>RacketPro</Brand>
## <Price>89.99</Price>
## <Variation_ID>502-A</Variation_ID>
## <Variation_Details>Material: Graphite, Color: Black</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Tennis Racket</Item_Name>
## <Item_ID>502</Item_ID>
## <Brand>RacketPro</Brand>
## <Price>89.99</Price>
## <Variation_ID>502-B</Variation_ID>
## <Variation_Details>Material: Aluminum, Color: Silver</Variation_Details>
## </Item>
## </Inventory>
# Read XML back into R
read_xml_data <- XML::xmlParse("C:\\Users\\HP\\Documents\\R projects\\Week 7\\xml_data_file.xml")
# Convert the XML back to a dataframe for verification
xml_root <- XML::xmlRoot(read_xml_data)
xml_to_df <- xmlToDataFrame(xml_root)
# Print the dataframe to verify
print(xml_to_df)## Category Item_Name Item_ID Brand Price Variation_ID
## 1 Electronics Smartphone 101 TechBrand 699.99 101-A
## 2 Electronics Smartphone 101 TechBrand 699.99 101-B
## 3 Electronics Laptop 102 CompuBrand 1099.99 102-A
## 4 Electronics Laptop 102 CompuBrand 1099.99 102-B
## 5 Home Appliances Refrigerator 201 HomeCool 899.99 201-A
## 6 Home Appliances Refrigerator 201 HomeCool 899.99 201-B
## 7 Home Appliances Washing Machine 202 CleanTech 499.99 202-A
## 8 Home Appliances Washing Machine 202 CleanTech 499.99 202-B
## 9 Clothing T-Shirt 301 FashionCo 19.99 301-A
## 10 Clothing T-Shirt 301 FashionCo 19.99 301-B
## 11 Clothing T-Shirt 301 FashionCo 19.99 301-C
## 12 Clothing Jeans 302 DenimWorks 49.99 302-A
## 13 Clothing Jeans 302 DenimWorks 49.99 302-B
## 14 Books Fiction Novel 401 - 14.99 401-A
## 15 Books Fiction Novel 401 - 14.99 401-B
## 16 Books Non-Fiction Guide 402 - 24.99 402-A
## 17 Books Non-Fiction Guide 402 - 24.99 402-B
## 18 Sports Equipment Basketball 501 SportsGear 29.99 501-A
## 19 Sports Equipment Tennis Racket 502 RacketPro 89.99 502-A
## 20 Sports Equipment Tennis Racket 502 RacketPro 89.99 502-B
## Variation_Details
## 1 Color: Black, Storage: 64GB
## 2 Color: White, Storage: 128GB
## 3 Color: Silver, Storage: 256GB
## 4 Color: Space Gray, Storage: 512GB
## 5 Color: Stainless Steel, Capacity: 20 cu ft
## 6 Color: White, Capacity: 18 cu ft
## 7 Type: Front Load, Capacity: 4.5 cu ft
## 8 Type: Top Load, Capacity: 5.0 cu ft
## 9 Color: Blue, Size: S
## 10 Color: Red, Size: M
## 11 Color: Green, Size: L
## 12 Color: Dark Blue, Size: 32
## 13 Color: Light Blue, Size: 34
## 14 Format: Hardcover, Language: English
## 15 Format: Paperback, Language: Spanish
## 16 Format: eBook, Language: English
## 17 Format: Paperback, Language: French
## 18 Size: Size 7, Color: Orange
## 19 Material: Graphite, Color: Black
## 20 Material: Aluminum, Color: Silver
# Convert to Parquet
arrow::write_parquet(mart_data, "parquet_data_file.parquet")
# Read Parquet back into R
imported_parquet_data <- arrow::read_parquet("C:\\Users\\HP\\Documents\\R projects\\Week 7\\parquet_data_file.parquet")
print(imported_parquet_data)## # A tibble: 20 × 7
## Category Item_Name Item_ID Brand Price Variation_ID Variation_Details
## <chr> <chr> <dbl> <chr> <dbl> <chr> <chr>
## 1 Electronics Smartpho… 101 Tech… 700. 101-A Color: Black, St…
## 2 Electronics Smartpho… 101 Tech… 700. 101-B Color: White, St…
## 3 Electronics Laptop 102 Comp… 1100. 102-A Color: Silver, S…
## 4 Electronics Laptop 102 Comp… 1100. 102-B Color: Space Gra…
## 5 Home Appliances Refriger… 201 Home… 900. 201-A Color: Stainless…
## 6 Home Appliances Refriger… 201 Home… 900. 201-B Color: White, Ca…
## 7 Home Appliances Washing … 202 Clea… 500. 202-A Type: Front Load…
## 8 Home Appliances Washing … 202 Clea… 500. 202-B Type: Top Load, …
## 9 Clothing T-Shirt 301 Fash… 20.0 301-A Color: Blue, Siz…
## 10 Clothing T-Shirt 301 Fash… 20.0 301-B Color: Red, Size…
## 11 Clothing T-Shirt 301 Fash… 20.0 301-C Color: Green, Si…
## 12 Clothing Jeans 302 Deni… 50.0 302-A Color: Dark Blue…
## 13 Clothing Jeans 302 Deni… 50.0 302-B Color: Light Blu…
## 14 Books Fiction … 401 - 15.0 401-A Format: Hardcove…
## 15 Books Fiction … 401 - 15.0 401-B Format: Paperbac…
## 16 Books Non-Fict… 402 - 25.0 402-A Format: eBook, L…
## 17 Books Non-Fict… 402 - 25.0 402-B Format: Paperbac…
## 18 Sports Equipme… Basketba… 501 Spor… 30.0 501-A Size: Size 7, Co…
## 19 Sports Equipme… Tennis R… 502 Rack… 90.0 502-A Material: Graphi…
## 20 Sports Equipme… Tennis R… 502 Rack… 90.0 502-B Material: Alumin…