NoPaste

Aufgabe_1.R

von tegula
SNIPPET_DESC:
Bitte Dateinamensendung .txt entfernen.
SNIPPET_CREATION_TIME:
07.09.2022 15:55:49
SNIPPET_PRUNE_TIME:
Unendlich

SNIPPET_TEXT:
  1. # Aufgabe 1: Bestimme, wie viele Buchstaben, die URL des dfde-Unterforums "Softwareentwicklung und -paketierung, Scripting" (<https://debianforum.de/forum/viewforum.php?f=34>) enthält. Zähle einmal mit und einmal ohne die Angabe des Protokolls ("https").
  2.  
  3. #' ----------------------------
  4. #' ----------------------------
  5.  
  6. # Tidyverse laden
  7. library(tidyverse)
  8.  
  9. #' ----------------------------
  10. #' ----------------------------
  11.  
  12. # (Hilfs-)funktionen definieren
  13.  
  14. ## Funktion definieren: Handelt es sich um eine HTTP-Url?
  15. is_http_url <- function(string) {
  16.   if (is.character(string)) {
  17.     string %>%
  18.       stringr::str_detect("^https://\\S+\\.\\S+$") %>%
  19.       return()
  20.   }
  21.   else {
  22.     return(NA)
  23.   }
  24. }
  25.  
  26.    
  27. ## Funktion definieren: Protokollangabe "http://" bzw. https:// entfernen
  28. cut_http <- function(string) {
  29.   if ((is_http_url(string))) {
  30.       match_matrix <- string %>%
  31.         stringr::str_match("^https?://(.*)$")
  32.       # Die Matches und zur ersten (und in diesem Fall auch einzigen) Gruppe (Teilausdruck) befinden sich in match_matrix[2].
  33.       return(match_matrix[2])
  34.   }
  35.   else {
  36.     return(NA)
  37.   }
  38. }
  39.  
  40. #' ----------------------------
  41. #' ----------------------------
  42.  
  43. # URL zum Forum "Softwareentwicklung und -paketierung, Scripting" im Workspace speichern
  44. url_dfde_skripting <- "https://debianforum.de/forum/viewforum.php?f=34"
  45.  
  46. #' ----------------------------
  47. #' ----------------------------
  48.  
  49. # Buchstaben (inklusive http bzw. https) zählen :
  50. if (is_http_url(url_dfde_skripting)) {
  51.   url_dfde_skripting %>%
  52.     str_count(pattern = "[:alpha:]")
  53. } else {
  54.   print(NA)
  55. }
  56.  
  57. #' ----------------------------
  58. #' ----------------------------
  59.  
  60. # Buchstaben (abzüglich http bzw. htpps) zählen:
  61. url_dfde_skripting %>%
  62.   cut_http() %>%
  63.   str_count(pattern = "[:alpha:]")
  64.  
  65. #

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN