Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate fake data #7

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions R/random-data-generation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
library(openxlsx)

prenoms <- c("Hector","Mari","Amance","Peter","Nathalie","Agathe","Romain","Eve","Marc","Enzo")

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=23,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=30,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=39,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=47,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=58,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=67,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=76,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=82,[commas_linter] Commas should always have a space after.

Check warning on line 3 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=3,col=89,[commas_linter] Commas should always have a space after.
noms <- c("Dupont","Nguyen","Martin","Garcia","Fouquier","Dubois","Jack","Boisu","Zaky","Mathy")

Check warning on line 4 in R/random-data-generation.R

View workflow job for this annotation

GitHub Actions / checks

file=R/random-data-generation.R,line=4,col=20,[commas_linter] Commas should always have a space after.
filiere <- c(rep("EMIR",30),rep("MICA",30),rep("CLASSIQUE",140))

#réponses possibles
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions names, variable names and comments should be written in english.

reponse_classique <- c("EII","MA","INFO","ET","GPM","GMA","GCU")
reponse_emir <- c("EII","INFO","GPM","ET")
reponse_mica <- c("GCU","MA","GMA","INFO")

choix_colonnes <- c(
paste0("Q02_Voeux->", reponse_classique),
paste0("Q03_VoeuxEMIR->", reponse_emir),
paste0("Q04_voeuxMICA->", reponse_mica)
)

nb_etudiants <- 200

df <- data.frame(
prenom = sample(prenoms, nb_etudiants, replace = TRUE),
nom = sample(noms, nb_etudiants, replace = TRUE),
filiere = sample(filiere, nb_etudiants, replace = TRUE)
)

generer_voeux <- function(filiere) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created functions should be documented using the roxigen2 standard.
You can read R/input.R on the dev branch, or this page to see how roxygen2 works.
After adding documentation, you can run the command: devtools::document().

result <- rep(NA, length(choix_colonnes))
names(result) <- choix_colonnes

if (filiere == "CLASSIQUE") {
classement <- sample(reponse_classique)
result[paste0("Q02_Voeux->", classement)] <- 1:7
} else if (filiere == "EMIR") {
classement <- sample(reponse_emir)
result[paste0("Q03_VoeuxEMIR->", classement)] <- 1:4
} else if (filiere == "MICA") {
classement <- sample(reponse_mica)
result[paste0("Q04_voeuxMICA->", classement)] <- 1:4
}
return(result)
}

# ajout des voeux
df_voeux <- t(apply(df, 1, function(row) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the code should be nested into a functions, except for your constants (such as noms, filiere or reponse_emir).

generer_voeux(row["filiere"])
}))
df_voeux <- as.data.frame(df_voeux)


# fusion
df_final <- cbind(df, df_voeux)

# affichage
write.xlsx(df_final,"resultatfinal.xlsx")
Loading